-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoProcessor.py
55 lines (42 loc) · 1.67 KB
/
VideoProcessor.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
# initiate the video source
video = 'C:/Work Files/Tech Forum/Facial Recognition/Train Videos/Vamsi.MOV'
DestinationFolder = 'C:\Work Files\Tech Forum\Facial Recognition\Training Pics'
# Function to check if the destination folder exists else creates it.
def FolderCheck(DestinationFolder):
ReturnMessage = ''
try:
if not os.path.exists(DestinationFolder):
os.makedirs(DestinationFolder)
ReturnMessage = 'Folder Created'
else:
ReturnMessage = 'Folder Exists'
# exit if there is an error creating the folder
except:
ReturnMessage = 'Error creating the destination folder.'
return (ReturnMessage)
def ProcessVideo(VideoFile, DestinationFolder, DebugFlag):
# Open the video and capture 30 frames at equal intervals.
# initiate the frame counter
ImageCounter = 0
FrameCounter = 0
Video = cv2.VideoCapture(VideoFile)
while Video.isOpened():
ret, frame = Video.read()
print(ret)
if ret:
# print(ret)
# if DebugFlag != 0:
print(os.path.join(DestinationFolder, f'frame{ImageCounter}.jpg Created'))
cv2.imwrite(os.path.join(DestinationFolder, f'frame{ImageCounter}.jpg'), frame)
FrameCounter += 10 # this will help the processor jump a few frames before capturing the next image.
Video.set(1, FrameCounter)
ImageCounter += 1
else:
print(ret)
Video.release()
break
return
FolderMessage = FolderCheck(DestinationFolder)
ProcessVideo(video, DestinationFolder, 1)