Last active
September 24, 2019 02:27
-
-
Save dreness/bc5e68bb8c0283ca0ef5e1e6be957397 to your computer and use it in GitHub Desktop.
make a video of a bunch of generated barcodes using #ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# make some barcodes, then use ffmpeg to make a video from the individual frames, | |
# to see how fast FirebaseML can recognize barcodes through the camera. | |
# https://github.com/azamsharp/FirebaseML.git | |
# barcode types | |
# code128 code39 ean ean13 ean14 ean8 gs1 | |
# gtin isbn isbn10 isbn13 issn itf jan pzn upc upca | |
# Available image formats | |
# Standard: svg | |
# PIL: BMP GIF JPEG MSP PCX PNG TIFF XBM | |
from barcode import generate, EAN13 | |
from barcode.writer import ImageWriter | |
import subprocess as sp | |
from random import randint | |
# python-barcode create -b ean13 -t png '1359747365823' test1 | |
# ean13 has 13 digits | |
DIGITS = 13 | |
# how many should we make? | |
NBARCODES = 100 | |
IMAGEDIR = "barcodes" | |
def mkDigits(count): | |
NUM = "" | |
while count > 0: | |
NUM = NUM + str(randint(0,9)) | |
count = count - 1 | |
return NUM | |
m13 = mkDigits(13) | |
print(m13) | |
HTML = open("barcodes.html", "w") | |
HTML.write("<html><body><center>") | |
options = { | |
'dpi': 501, | |
'module_height': 8, | |
'quiet_zone': 10, | |
'text_distance': 0 | |
} | |
for i in range(1, NBARCODES): | |
code = mkDigits(13) | |
# generate(EAN13, code, writer=None, output=code, writer_options=None, text=None, pil=False) | |
name = generate('EAN13', code, output=IMAGEDIR+"/"+str(i), writer=ImageWriter(), writer_options=options) | |
HTML.write(f"<br><img src={name}>") | |
HTML.write("</center></body></html>") | |
HTML.close() | |
# ffmpeg -r 15 -f image2 -i barcodes/%d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p barcodes.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment