File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ # File name: video_jpeg_converter.py
2+ # Objective: To return a set of continuous JPEG images from an input video (useful for annotation of videos)
3+
4+ from imutils import paths
5+ import cv2
6+ import os
7+
8+ # Path for input videos (which will be converted to a series of JPEG images)
9+ dataPath = str (input ("Copy the path to your video input data and paste it here: " ))
10+
11+ # Path for output JPEG images
12+ outPath = str (input ("Copy the path to your output folder storing the JPEG images and paste it here: " ))
13+
14+ for classPath in os .listdir (dataPath ):
15+ clipPaths = os .listdir (dataPath + "\\ " + classPath )
16+ os .mkdir ((outPath + '\\ ' + classPath ))
17+
18+ k = 1
19+ for clips in clipPaths :
20+ os .mkdir ((outPath + '\\ ' + classPath + '\\ ' + clips ))
21+ os .chdir ((outPath + '\\ ' + classPath + '\\ ' + clips ))
22+
23+ f = dataPath + "\\ " + classPath + "\\ " + clips
24+ cam = cv2 .VideoCapture (f )
25+ ret , frame = cam .read ()
26+ currentframe = 0
27+ i = 0
28+
29+ # a variable to set how many frames you want to skip
30+ frame_skip = 5 # Since the videos are in 30 FPS, and we want 10 frames per clip
31+
32+ while cam .isOpened ():
33+ ret , frame = cam .read ()
34+ k += 1
35+ if not ret :
36+ break
37+ if (i > frame_skip - 1 ):
38+ cv2 .imwrite (classPath + '_' + clips + '_' + str (k ) + '.jpg' , frame )
39+ i = 0
40+ continue
41+ i += 1
42+
43+ cam .release ()
44+ cv2 .destroyAllWindows ()
You can’t perform that action at this time.
0 commit comments