尝试使用opencv从网络摄像头捕获视频时出现此错误。这是我正在使用的代码:
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main( int argc, const char** argv ) {
CvCapture *capture = cvCaptureFromCAM(0);
IplImage *frame;
cvNamedWindow("test");
while ( 1)
{
frame = cvQueryFrame(capture) ;
cvShowImage("test", frame);
int key = cvWaitKey(1);
if ( key == 27 ) break; // ESC key was pressed
}
// Memory deallocation
cvReleaseCapture(&capture);
cvDestroyWindow("test");
return 0;
}
错误发生在cvShowImage(“text”,frame):
OpenCV错误:cvGetMat中的空指针(传递NULL数组指针), 文件 /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.6.1/modules/core/src/array.cpp, 第2382行libc ++ abi.dylib:终止调用抛出异常 (LLDB)
错误是什么以及如何解决?
答案 0 :(得分:0)
首先,您应检查索引0处是否有设备,如此
if (!capture)
{
// print error and exit
cout << "ERROR: Capture is null!\n";
return -1;
}
其次,:
while ( capture)
{
frame = cvQueryFrame(capture) ;
cvShowImage("test", frame);
int key = cvWaitKey(1);
if ( key == 27 ) break; // ESC key was pressed
}
希望这有帮助