Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 0f88588

Browse files
authored
Merge pull request #53 from phileinSophos/slave_1
Capture Video Frames
2 parents 5a66c5d + 1ea3bd3 commit 0f88588

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Capture Video Frames
2+
##### Execute
3+
`python capture_video_frames.py <video_file>`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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()

0 commit comments

Comments
 (0)