-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_to_qr.py
37 lines (31 loc) · 1.19 KB
/
video_to_qr.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
import cv2
from os import mkdir
from os.path import join, isdir
from tqdm import tqdm
from qr_to_file import init
class VideoToImagesConverter:
def img_from_video(self, video_name, save_dir, frame_interval, frame_size):
cap = cv2.VideoCapture(video_name)
if not isdir(save_dir):
mkdir(save_dir)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
if frame_count == 0:
exit("Video file not found")
output_index = 0 # Counter for output image filenames
for i in tqdm(range(0, frame_count, frame_interval), desc="Extracting"):
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
ret, img = cap.read()
if ret:
img = cv2.resize(img, frame_size)
cv2.imwrite(join(save_dir, 'image%d.png' % output_index), img)
output_index += 1
cap.release()
def videostart(name):
video_name = name
save_dir = "extracted_images"
frame_size = (640, 480)
frame_interval = 5
# Create an instance of the class and run the conversion
converter = VideoToImagesConverter()
converter.img_from_video(video_name, save_dir, frame_interval, frame_size)
init()