声明失败(size.width> 0&&& size.height> 0) [英] Assertion failed (size.width>0 && size.height>0)

查看:3222
本文介绍了声明失败(size.width> 0&&& size.height> 0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenCV 2.4.7 的Visual Studio Express 2013,并遵循此教程



我花了几个小时在网上搜索解决方案,包括所有相关的SO问题。我尝试了:




  • 的返回值VideoCapture :: open is 1


  • 延长waitKey窗口的尺寸



  • 在Visual C ++上创建另一个项目




但没有运气,请帮助!



这是我的代码:

  #include< opencv / cv.h> 
#include< opencv / highgui.h>
#include< iostream>

using namespace std;
using namespace cv;

int main(){
Mat image;

VideoCapture cap;
int camOpen = cap.open(CV_CAP_ANY);

namedWindow(window,CV_WINDOW_AUTOSIZE);

while(true){
cap>>图片;

imshow(window,image);

// delay 33ms
waitKey(33);
}

}



当我编译并运行它时,我收到以下错误:


OpenCV错误:Assertion failed(size.width> 0&& size.height> 0) cv :: imshow,file ........ \opencv\modules\highgui\src\window.cpp,第261行


错误发生在 imshow(window,image); 行。当我评论它,没有投诉。






更新:



一个合理的解释为什么这个错误发生,我的网络摄像头需要时间开始,这就是为什么image.empty()最初是true,因此abort()函数被调用退出程序。



使用代码

  if(!image.empty()){
imshow(window,image);
}

我们可以等待相机启动


我试过你的代码,对我来说它工作(它可视化当前的网络摄像头输入)!

我在Visual Studio 2012上运行它Ultimate with OpenCV 2.4.7。
$ $ $ b ...

出现此错误是因为图片为空,请尝试此操作:

  while(true){
cap>>图片;

if(!image.empty()){
imshow(window,image);
}

// delay 33ms
waitKey(33);
}

也许您从网络摄像头收到的第一张图片是空的。在这种情况下,imshow不会抛出错误。因此,希望下一个输入图像不为空。


I'm using Visual Studio Express 2013 with OpenCV 2.4.7, following this tutorial.

I have spent hours searching the web for solutions, including all of the relevant SO questions. I have tried:

  • the return value of VideoCapture::open is 1

  • extending the waitKey() delay to 50ms and later 500ms

  • setting the dimensions of the window

  • creating another project on Visual C++

  • opening an existing image instead of reading from camera (same error)

but no luck, please help!

Here's my code:

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>

using namespace std;
using namespace cv;

int main() {
    Mat image;

    VideoCapture cap;
    int camOpen = cap.open(CV_CAP_ANY);

    namedWindow("window", CV_WINDOW_AUTOSIZE);

    while (true) {
        cap >> image;

        imshow("window", image);

    // delay 33ms
    waitKey(33);        
    }

}

As I compiled and ran it, I got the following error:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ........\opencv\modules\highgui\src\window.cpp, line 261

Error occurs at the line imshow("window", image);. When I commented it out, there are no complaints.


UPDATES:

A plausible explanation of why this error occured was that my webcam takes time to start, which is why image.empty() is true initially, hence the abort() function was called to exit the program.

With the code

if (!image.empty()) {
    imshow("window", image);
}

we can wait for the camera to start

解决方案

I tried your code and for me it works (it visualizes the current webcam input)!
I ran it on Visual Studio 2012 Ultimate with OpenCV 2.4.7.
...
The error occurs because the image is empty, so try this:

while (true) {
    cap >> image;

    if(!image.empty()){
        imshow("window", image);
    }

// delay 33ms
waitKey(33);        
}

Maybe the first image you receive from your webcam is empty. In this case imshow will not throw an error. So hopefully the next input images are not empty.

这篇关于声明失败(size.width&gt; 0&amp;&amp;&amp; size.height&gt; 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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