python opencv 视频流转图片

import json
import os
from glob import glob
from tqdm import tqdm
from PIL import Image
import cv2


videoFile = 'video/4-lasi-video-2.mp4'
outputFile = 'frame/frame'
vc = cv2.VideoCapture(videoFile)
c = 1
if vc.isOpened():
    rval, frame = vc.read()
else:
    print('openerror!')
    rval = False

timeF = 1  #视频帧计数间隔次数
while rval:
#     print(1)
    print(c)
    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()


你可能感兴趣的:(人工智能)