This repository was archived by the owner on May 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
projects/Capture_Video_Frames Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ # Capture Video Frames
2+ ##### Execute
3+ ` python capture_video_frames.py <video_file> `
Original file line number Diff line number Diff line change 1+ import os
2+ import shutil
3+ import sys
4+ import cv2
5+
6+ class FrameCapture :
7+ '''
8+ Class definition to capture frames
9+ '''
10+ def __init__ (self , file_path ):
11+ '''
12+ initializing directory where the captured frames will be stored.
13+ Also truncating the directory where captured frames are stored, if exists.
14+ '''
15+ self .directory = "captured_frames"
16+ self .file_path = file_path
17+ if os .path .exists (self .directory ):
18+ shutil .rmtree (self .directory )
19+ os .mkdir (self .directory )
20+
21+ def capture_frames (self ):
22+ '''
23+ This method captures the frames from the video file provided.
24+ This program makes use of openCV library
25+ '''
26+ cv2_object = cv2 .VideoCapture (self .file_path )
27+
28+ frame_number = 0
29+ frame_found = 1
30+
31+ while frame_found :
32+ frame_found , image = cv2_object .read ()
33+ capture = f'{ self .directory } /frame{ frame_number } .jpg'
34+ cv2 .imwrite (capture , image )
35+
36+ frame_number += 1
37+
38+ if __name__ == '__main__' :
39+ file_path = sys .argv [1 ]
40+ fc = FrameCapture (file_path )
41+ fc .capture_frames ()
You can’t perform that action at this time.
0 commit comments