-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutOutFromVideo.py
61 lines (48 loc) · 1.4 KB
/
cutOutFromVideo.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
56
57
58
59
60
61
# coding:UTF-8
"""
-------------------------------------
# -*- coding: utf-8 -*-
# @Time : 2020/10/1 15:44:12
# @Author : Giyn
# @Email : giyn.jy@gmail.com
# @File : video_processing.py
# @Software: PyCharm
-------------------------------------
"""
import cv2
import logging
# log information settings
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s: %(message)s')
def save_image(num, image):
"""Save the images.
Args:
num: serial number
image: image resource
Returns:
None
"""
image_path = 'cutoutFromVideoResult/{}.jpg'.format(str(num))
cv2.imwrite(image_path, image)
file_path = 'video.avi'
vc = cv2.VideoCapture(file_path) # import video files
# determine whether to open normally
if vc.isOpened():
ret, frame = vc.read()
else:
ret = False
count = 0 # count the number of pictures
frame_interval = 14 # video frame count interval frequency
frame_interval_count = 0
# loop read video frame
while ret:
ret, frame = vc.read()
# store operation every time f frame
if frame_interval_count % frame_interval == 0:
save_image(count, frame)
logging.info("num:" + str(count) + ", frame: " +
str(frame_interval_count))
count += 1
frame_interval_count += 1
cv2.waitKey(1)
vc.release()