OpenCV_Python - Write Code for Read the Saved Vide

2019-08-29 13:14发布

问题:

I am a newbie in OpenCV using Python. I am currently working with a project related opencv using python language. I would like to read a saved video after i globed a set of frame sequence. However, I am getting an error when I execute the program for read the video, can any of you please shed some light on what might be wrong? Thank you. This is my sample code:

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.")

Note: The saved video named 'test.avi' is not problem and able to play at the saved file location. The problem now is i would like to write a program code to read the video and play it. However i am getting an error.

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

This is the error:

 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

回答1:

Get a try at modifying the Opencv code: https://github.com/opencv/opencv/pull/11146/commits/c6cf7f80808eee8cebec4c8417b2d99714defcac

opencv/modules/videoio/src/container_avi.cpp - CV_Assert(chunk.m_size <= 0xFFFF); + CV_Assert(chunk.m_size <= 67108864);



标签: resize