这是我的代码:
#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);