为什么我使用OpenCv的代码从视频中提取较少的帧数

问题描述

当我使用OpenCv的以下内置属性来计算视频的帧数时,其显示正确的结果。

video = cv2.VideoCapture(path)
total = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

但是,当我尝试保存所有这些帧时,它存储的帧数较少。下面是保存框架的另一代码-

def ExtractFrames(self,videoPath):
    srcVideo = cv2.VideoCapture(videoPath)
    try:
        if not os.path.exists('VideoFrames'):
            os.makedirs('VideoFrames')         
    except OSError:
        print('Error: Creating directory.')

    currentframe = 0

    while (True):
        success,image = srcVideo.read()      
        if success:
            fileName = './VideoFrames/frame' + str(currentframe) + '.jpg'
            self.lstVideoFrames.append(fileName)
            cv2.imwrite(fileName,image)
            currentframe += 1  
        else:
            break

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...