简体   繁体   English

播放.avi时发生OpenCV Python断言失败错误

[英]OpenCV Python Assertion failed error when playing .avi

I am just beginning to learn OpenCV and am working through the tutorials here: https://opencv24-python-tutorials.readthedocs.io/en/stable/py_tutorials/py_gui/py_video_display/py_video_display.html 我才刚刚开始学习OpenCV,并且正在这里学习教程: https : //opencv24-python-tutorials.readthedocs.io/en/stable/py_tutorials/py_gui/py_video_display/py_video_display.html

This is the code I've written to play the sample video. 这是我编写的用于播放示例视频的代码。

import numpy as np
import cv2

cap = cv2.VideoCapture('samples/vtest.avi')

while (cap.isOpened()):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame', gray)
    if cv2.waitkey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

This is the error message I get: 这是我收到的错误消息:

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/opencv-20161020-7399-1yrk4nm/opencv-2.4.13.1/modules/imgproc/src/color.cpp, line 3739
Traceback (most recent call last):
  File "vidFile_tutorial.py", line 14, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /tmp/opencv-20161020-7399-1yrk4nm/opencv-2.4.13.1/modules/imgproc/src/color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cvtColor

I'm unsure that the problem is an assertion fail error since I've chosen the file as specified by the tutorial. 由于我已经选择了教程指定的文件,因此我不确定问题是否是断言失败错误。 Moreover, when I attempt to play vtest.avi manually I encounter a codec error with QuickTime. 此外,当我尝试手动播放vtest.avi时,遇到QuickTime编解码器错误。 Therefore, I suspect it's video codec issues with OpenCV. 因此,我怀疑这是OpenCV的视频编解码器问题。 But I'm unsure if the diagnosis is correct and how I would go about fixing it. 但是我不确定诊断是否正确以及如何解决它。

Thanks in advance. 提前致谢。

Okay, So I've managed to resolve the issue by using OpenCV 3.1.0 rather than 2.4.13.1. 好的,所以我设法使用OpenCV 3.1.0(而不是2.4.13.1)解决了这个问题。

With OpenCV 3.1.0 everything works fine. 使用OpenCV 3.1.0,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM