视频转换成图片

import cv2


def getFrame(videoPath, svPath):
    cap = cv2.VideoCapture(videoPath)
    numFrame = 0
    while True:
        if cap.grab():
            flag, frame = cap.retrieve()
            if not flag:
                continue
            else:
                # cv2.imshow('video', frame)
                numFrame += 1
                if numFrame % 20 == 0:
                    newPath = svPath + str(numFrame) + ".jpg"
                    cv2.imencode('.jpg', frame)[1].tofile('./image/' + newPath)
        if cv2.waitKey(10) == 27:
            break


getFrame('./video/ddddd.mp4', './dd_')
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页