简体   繁体   English

OpenCV错误:在imshow中断言失败(size.width> 0 && size.height> 0)

[英]OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow

I am running the following code on Raspberry Pi with pi camera, I have the broadcom drivers for it and all, but I am getting an error. 我正在使用pi相机在Raspberry Pi上运行以下代码,我具有适用于所有功能的Broadcom驱动程序,但出现错误。 Perhaps something to do with the dimensions of the video feed, but I do not know how to set it on Linux. 也许与视频提要的尺寸有关,但是我不知道如何在Linux上进行设置。

Code: 码:

import cv2
import numpy as np

cap = cv2.VideoCapture()
while True:
    ret, img = cap.read()
    cv2.imshow('img', img)
    if cv2.waitKey(0) & 0xFF == ord('q):
        break

Error: 错误:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, 
file /home/pi/opencv-3.3.0/modules/highgui/src/window.cpp, line 325
Traceback (most recent call last):
  File "check_picam_with_opencv.py", line 10, in <module>
    cv2.imshow('img', img)
cv2.error: /home/pi/opencv-3.3.0/modules/highgui/src/window.cpp:325: error: 
(-215) size.width>0 && size.height>0 in function imshow

Provide an id to VideoCapture . VideoCapture提供一个ID。

cap = cv2.VideoCapture(0)

Also check the value of ret , see if it's TRUE or FALSE 还要检查ret的值,看看它是TRUE还是FALSE

print (ret)

Edit: 编辑:

To capture a video, you need to create a VideoCapture object. 要捕获视频,您需要创建一个VideoCapture对象。 Its argument can be either the device index or the name of a video file. 它的参数可以是设备索引或视频文件的名称。 Device index is just the number to specify which camera. 设备索引只是指定哪个摄像机的编号。

cap = cv2.VideoCapture(0)

To check whether the cap has been initialized or not, you can use cap.isOpened() function, which returns True for successful initialization and False for failure. 要检查cap是否已初始化,可以使用cap.isOpened()函数,该函数返回True表示初始化成功,返回False表示失败。

if cap.isOpened() == False:
    print ("VideoCapture failed")

cap.read() returns a bool (True/False). cap.read()返回布尔值(True / False)。 If frame is read correctly, it will be True. 如果正确读取帧,它将为True。 So you can check end of the video by checking this return value. 因此,您可以通过检查此返回值来检查视频的结尾。

ret, frame = cap.read()
if ret == False:
    print("Frame is empty")

Further reading here . 在这里进一步阅读。

暂无
暂无

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

相关问题 OpenCV 错误:(-215:断言失败)size.width>0 && size.height>0 in function 'imshow' - OpenCV error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow' opencv 错误:(-215:断言失败)size.width&gt;0 &amp;&amp; size.height&gt;0 in function 'cv::imshow' - opencv error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' 相机流 - OpenCV 错误:(-215:断言失败)size.width>0 && size.height>0 in function 'cv::imshow' - Camera Streaming - OpenCV error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' OpenCV错误:在cv :: imshow(Python)中断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0) - OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow (Python) OpenCV(4.2.0) 错误: (-215:Assertion failed) size.width&gt;0 &amp;&amp; size.height&gt;0 in function 'cv::imshow' - OpenCV(4.2.0) error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' 错误:(-215:断言失败)函数“imshow”中的 size.width&gt;0 &amp;&amp; size.height&gt;0 - error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow' 错误:(-215:断言失败)函数 cv::imshow 中的 size.width&gt;0 &amp;&amp; size.height&gt;0 - error: (-215:Assertion failed) size.width>0 && size.height>0 in function cv::imshow 断言失败:function imshow 中的 size.width&gt;0 &amp;&amp; size.height&gt;0 - Assertion failure : size.width>0 && size.height>0 in function imshow OpenCV 错误:断言失败(size.width&gt;0 &amp;&amp; size.height&gt;0)python - OpenCV Error: Assertion failed (size.width>0 && size.height>0) python opencv python 错误:断言失败 (size.width>0 && size.height>0) - opencv python error: Assertion failed (size.width>0 && size.height>0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM