利用opencv库使用Python将视频逐帧转为图片
做成型的语义分割软件需要,写了一个,在博客记录一下
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)
空谈误国,实干兴邦
个人博客: https://www.0error.net/