opencv error:未知函数线261中的断言失败(size.width> 0&& size.height> 0) [英] opencv error: assertion failed (size.width>0 && size.height>0) in unknown function line 261
本文介绍了opencv error:未知函数线261中的断言失败(size.width> 0&& size.height> 0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
#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
在窗口中.cpp,第261行是:
In window.cpp, line 261 is:
CV_Assert(size.width>0 && size.height>0);
我解决了我的问题。
首先,您可以添加此代码
I solved my problem. firstly, you can add this code
VideoCapture cap;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
然后在while循环中添加此代码:
then add this code in while loop:
cap.read(image);
推荐答案
(size.width& 0&&& size.height> 0)
表示在那里有一个空的 Mat
。在这种情况下,必须是 image
为空,因为无法打开相机。检查 VideoCapture :: open
返回值。
(size.width>0 && size.height>0)
means that there is an empty Mat
over there. In this case, it must be that image
is empty because the camera couldn't be opened. Check VideoCapture::open
return value.
这篇关于opencv error:未知函数线261中的断言失败(size.width> 0&& size.height> 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文