这是我的代码:
#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
返回值。
关于c++ - 未知函数行 261 中的 opencv 错误 : assertion failed (size. width>0 && size.height>0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18766025/