Update Barcode_Generator.py
This commit is contained in:
parent
67a08fcf17
commit
8d7882ad1c
|
|
@ -1,29 +1,35 @@
|
|||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
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):
|
||||
scaled = img.astype('uint32')
|
||||
squared = scaled**2
|
||||
avgsq = np.average(squared, axis=0)
|
||||
avgsq = np.average(squared, axis=1)
|
||||
return np.sqrt(avgsq).astype('uint8')
|
||||
|
||||
|
||||
def collect_frames(movie):
|
||||
res = []
|
||||
s, i = movie.read()
|
||||
def movie_iter(movie_name, frames_to_skip):
|
||||
movie=cv2.VideoCapture(f"{movie_name}.mp4") #
|
||||
s, f = 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
|
||||
yield f
|
||||
for i in range(frames_to_skip):
|
||||
movie.read()
|
||||
s,f = movie.read()
|
||||
|
||||
|
||||
def elab(movie_it):
|
||||
with Pool(8) as p:
|
||||
res = p.map(frame_avg, movie_it, chunksize=100)
|
||||
|
||||
return res
|
||||
|
||||
complete = collect_frames(movie)
|
||||
|
||||
c = np.array(complete)
|
||||
|
|
@ -32,4 +38,4 @@ cc = c.swapaxes(0, 1)
|
|||
|
||||
i = Image.fromarray(cc, mode='RGB')
|
||||
|
||||
i.save('barcode.jpg') # Name of your output
|
||||
i.save('multip_test_steven.jpg')
|
||||
|
|
|
|||
Loading…
Reference in New Issue