Update Barcode_Generator.py

This commit is contained in:
Carmelo Sarta 2019-09-26 16:49:22 +02:00 committed by GitHub
parent 67a08fcf17
commit 8d7882ad1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 13 deletions

View File

@ -1,29 +1,35 @@
import sys
import cv2 import cv2
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from multiprocessing import Pool
import os
movie = cv2.VideoCapture("movie.mp4") # VideoCapture take as argument any video files, image sequences or cameras os.system("taskset -p 0xff %d" % os.getpid())
def frame_avg(img): def frame_avg(img):
scaled = img.astype('uint32') scaled = img.astype('uint32')
squared = scaled**2 squared = scaled**2
avgsq = np.average(squared, axis=0) avgsq = np.average(squared, axis=1)
return np.sqrt(avgsq).astype('uint8') return np.sqrt(avgsq).astype('uint8')
def movie_iter(movie_name, frames_to_skip):
def collect_frames(movie): movie=cv2.VideoCapture(f"{movie_name}.mp4") #
res = [] s, f = movie.read()
s, i = movie.read()
while s: while s:
res.append(frame_avg(i)) yield f
s, i = movie.read() for i in range(frames_to_skip):
for i in range(30): movie.read()
if s: s,f = movie.read()
s, i = movie.read()
return res
def elab(movie_it):
with Pool(8) as p:
res = p.map(frame_avg, movie_it, chunksize=100)
return res
complete = collect_frames(movie) complete = collect_frames(movie)
c = np.array(complete) c = np.array(complete)
@ -32,4 +38,4 @@ cc = c.swapaxes(0, 1)
i = Image.fromarray(cc, mode='RGB') i = Image.fromarray(cc, mode='RGB')
i.save('barcode.jpg') # Name of your output i.save('multip_test_steven.jpg')