利用opencv库使用Python将视频逐帧转为图片

本文最后更新于:2023年11月8日 中午

做成型的语义分割软件需要,写了一个

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
import cv2


def video2pic(videoFile, outputFile):
vc = cv2.VideoCapture(videoFile)
c = 1
if vc.isOpened():
rval, frame = vc.read()
else:
print('error open video!')
rval = False

timeF = 100 # 帧率间隔
while rval:
print(1)
rval, frame = vc.read()
if c % timeF == 0:
print(2)
cv2.imwrite(outputFile + str(int(c / timeF)) + '.jpg', frame)
c += 1
cv2.waitKey(1)
vc.release()

if __name__ == '__main__':
videoFile = './test.mp4' # 输入路径
outputFile = './video2pic_res/frame' # 输出路径
video2pic(videoFile, outputFile)

利用opencv库使用Python将视频逐帧转为图片
https://www.0error.net/2023/05/60427.html
作者
Jiajun Chen
发布于
2023年5月22日
许可协议