繁体   English   中英

opencv错误:未知函数行261中的断言失败(size.width> 0 && size.height> 0)

[英]opencv error: assertion failed (size.width>0 && size.height>0) in unknown function line 261

这是我的代码:

#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;

int main(){
    //create matrix to store image
    Mat image;

    //initialize capture    
    VideoCapture cap(0);
    cap.open(0);

    //create window to show image   
    namedWindow("window",1);

    while(1){   
        //copy webcam stream to image
        cap>>image;

        //print image to screen     
        imshow("window",image); //Error line

        //delay 33ms
        waitKey(33);
    }
}

我得到的错误:

opencv error: assertion failed (size.width>0 && size.height>0) in unknown function
file...\opencv\modules\highgui\src\window.cpp line 261

在window.cpp中,第261行是:

CV_Assert(size.width>0 && size.height>0);

我解决了我的问题。 首先,您可以添加此代码

VideoCapture cap;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480); 

然后在while循环中添加以下代码:

cap.read(image);

(size.width>0 && size.height>0)表示那上面有一个空的Mat 在这种情况下,必须是该image为空,因为无法打开相机。 检查VideoCapture::open返回值。

cap.open(0);
Sleep(1000);  // Wait for response of camera, don't forget to #include <windows.h>

CHEARS

暂无
暂无

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

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