From 67a08fcf176b0066e30073eb8ba76a3a6080da99 Mon Sep 17 00:00:00 2001 From: Carmelo Sarta Date: Thu, 26 Sep 2019 16:46:56 +0200 Subject: [PATCH] Create Barcode_Generator.py Serial implementation. Slow but well-oiled. --- Barcode_Generator.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Barcode_Generator.py diff --git a/Barcode_Generator.py b/Barcode_Generator.py new file mode 100644 index 0000000..8132137 --- /dev/null +++ b/Barcode_Generator.py @@ -0,0 +1,35 @@ +import cv2 +import numpy as np +from PIL import Image + +movie = cv2.VideoCapture("movie.mp4") # VideoCapture take as argument any video files, image sequences or cameras + + +def frame_avg(img): + scaled = img.astype('uint32') + squared = scaled**2 + avgsq = np.average(squared, axis=0) + return np.sqrt(avgsq).astype('uint8') + + +def collect_frames(movie): + res = [] + s, i = movie.read() + while s: + res.append(frame_avg(i)) + s, i = movie.read() + for i in range(30): + if s: + s, i = movie.read() + return res + + +complete = collect_frames(movie) + +c = np.array(complete) + +cc = c.swapaxes(0, 1) + +i = Image.fromarray(cc, mode='RGB') + +i.save('barcode.jpg') # Name of your output