我是使用Python的OpenCV新手。我目前正在使用python语言处理与opencv相关的项目。在我完成一组帧序列之后,我想阅读一个保存的视频。但是,当我执行读取视频的程序时,我收到错误,你们中的任何人都可以对可能出错的内容有所了解吗?谢谢。这是我的示例代码:
import cv2
import numpy as np
import os
import glob as gb
filename = "VideoDataSet/dynamicBackground/canoe/input"
img_path = gb.glob(filename)
videoWriter = cv2.VideoWriter('test.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 25,(640,480))
for path in img_path:
img = cv2.imread(path)
img = cv2.resize(img,(640,480))
videoWriter.write(img)
print(path)
print ("you are success create.")
注意:已保存的视频名为' test.avi'没问题,能够在保存的文件位置播放。现在的问题是我想写一个程序代码来阅读视频并播放它。但是我收到了错误。
inputVideoName = 'test.avi'
cap = cv2.VideoCapture(inputVideoName)
if (cap.isOpened() == False):
print("Error opening video stream or file!")
while(True):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Display Video Clip',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):break
这是错误:
Error: OpenCV(3.4.1) Error: Assertion failed (chunk.m_size <= 0xFFFF) in
cv::AVIReadContainer::readFrame, file D:\Build\OpenCV\opencv-
3.4.1\modules\videoio\src\container_avi.cpp, line 514
答案 0 :(得分:0)
尝试修改Opencv代码: https://github.com/opencv/opencv/pull/11146/commits/c6cf7f80808eee8cebec4c8417b2d99714defcac
的OpenCV /模块/ videoio / SRC / container_avi.cpp - CV_Assert(chunk.m_size&lt; = 0xFFFF); + CV_Assert(chunk.m_size&lt; = 67108864);