OpenCV_Python - 编写读取保存视频的代码 (cv2.VideoWriter()) [英] OpenCV_Python - Write Code for Read the Saved Video (cv2.VideoWriter())

查看:166
本文介绍了OpenCV_Python - 编写读取保存视频的代码 (cv2.VideoWriter())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用 Python 的 OpenCV 新手.我目前正在使用 python 语言处理与 opencv 相关的项目.我想在我对一组帧序列进行全球化后阅读保存的视频.但是,当我执行程序以读取视频时出现错误,请问你们中的任何人都可以说明可能出现的问题吗?谢谢你.这是我的示例代码:

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

注意:保存的名为test.avi"的视频没有问题,可以在保存的文件位置播放.现在的问题是我想编写一个程序代码来读取视频并播放它.但是我收到了一个错误.

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

这是错误:

 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

推荐答案

尝试修改 Opencv 代码:https://github.com/opencv/opencv/pull/11146/c6cf7f80808eee8cebec4c8417b2d99714defcac

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);

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

这篇关于OpenCV_Python - 编写读取保存视频的代码 (cv2.VideoWriter())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆