-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavg_img_generation.py
30 lines (28 loc) · 1.06 KB
/
avg_img_generation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import cv2
import numpy as np
target_dir = 'n6'
for f in os.listdir(target_dir):
if os.path.isdir(target_dir + '/' + f) and f.startswith('output_'):
print(f)
avg_created = False
for f2 in os.listdir(target_dir + '/' + f):
if f2.endswith('.avi'):
cap = cv2.VideoCapture(target_dir + '/' + f + '/' + f2)
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
frame = np.float32(frame)
if not avg_created:
avg_img = frame
avg_count = 1
avg_created = True
else:
avg_count += 1
avg_img += (frame - avg_img) / avg_count
else:
break
cap.release()
if avg_created:
avg_img = np.uint8(np.round(avg_img))
cv2.imwrite(target_dir + '/' + f + '/avg_img.jpg', avg_img)