-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (37 loc) · 1.5 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import cv2
import os
import numpy as np
FOLDER = input('path: ')
SALT_FRAMES = int(input('how many salt frames: '))
PATH_FRAMES = './frames'
if not os.path.exists(PATH_FRAMES):
os.makedirs(PATH_FRAMES)
os.chdir(PATH_FRAMES)
ACTUAL = os.getcwd()
for root, dirs, files in os.walk(FOLDER):
for file in files:
if '.mp4' in file:
print(f'actual file: {file}')
cap = cv2.VideoCapture(os.path.join(root, file))
if (cap.isOpened() == False):
print("Error opening video stream or file")
count = 0
controller = 0
while(cap.isOpened()):
if not os.path.exists(os.path.join(ACTUAL, file.replace('.mp4', ''))):
os.makedirs(os.path.join(ACTUAL, file.replace('.mp4', '')))
if os.getcwd() != os.path.join(ACTUAL, file.replace('.mp4', '')):
os.chdir(os.path.join(ACTUAL, file.replace('.mp4', '')))
ret, frame = cap.read()
if ret == True:
if count % SALT_FRAMES == 0:
cv2.imwrite("frame%d.jpg" % controller, frame)
controller += 1
cv2.imshow(f'{file}',frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
count += 1
else:
break
cap.release()
cv2.destroyAllWindows()