faster, with smoothing, col only has one color

This commit is contained in:
Askill 2019-09-29 18:18:06 +02:00
parent 2490642701
commit a29ef6f9ec
2 changed files with 60 additions and 0 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
.vscode/launch.json
1.mov
1.mp4
2.mp4
3.mp4
4.mp4
test.png
test2.png

44
new.py Normal file
View File

@ -0,0 +1,44 @@
import cv2
import numpy as np
from PIL import Image
src = "1.mov"
target = "test.png"
video = cv2.VideoCapture(src)
FPS = 30
smoothing = 1
stackFactor = 100
def average_frame(img):
avg_color_per_row = np.average(img, axis=0)
avg_color = np.average(avg_color_per_row, axis=0)
return avg_color
def make_array(video):
result_array = []
success, image = video.read()
counter = 0
while success:
if counter%FPS == 0:
result_array.append(average_frame(image))
success, image = video.read() # image is of type numpy array
counter += 1
return np.asarray(result_array, dtype = np.uint8)
# convert video to 1 x #ofFrames array
res_arr = make_array(video)
# rotate to make it horizontal
rotated = np.swapaxes(res_arr,0,1)
# stack the rows
tiled = np.tile([res_arr], (stackFactor, 1, 1))
# blur the image in y-axis
blured = cv2.blur(tiled, (smoothing , 1))
# converti image to rgb from bgr
im_rgb = cv2.cvtColor(blured, cv2.COLOR_BGR2RGB)
# create image from array
im = Image.fromarray(im_rgb, mode='RGB')
# save image
im.save(target)