1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import cv2

video_path = r'D:\ApowerREC\20220808_153435.mp4' # 视频地址
output_path = r'D:/ApowerREC/False/' # 输出文件夹
interval = 3 # 每间隔10帧取一张图片

if __name__ == '__main__':
num = 1
vid = cv2.VideoCapture(video_path)
while vid.isOpened():
is_read, frame = vid.read()
if is_read:
if num % interval == 1:
file_name = '%08d' % num
cv2.imwrite(output_path + str(file_name) + '.jpg', frame)
# 00000111.jpg 代表第111帧
cv2.waitKey(1)
num += 1

else:
break

拿来水数据集制作的脚本。interval实际上设置的太小了,应该要放到10左右,才不会有太多重合。

视频转图片,根据interval取图片,按照24帧/S。