c++ - Opencv: Null pointer (NULL array pointer is passed) in cvGetMat -
i'm getting error when trying capture video webcam using opencv. code i'm using:
#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 pressed } // memory deallocation cvreleasecapture(&capture); cvdestroywindow("test"); return 0; }
the error occur @ cvshowimage("text", frame):
opencv error: null pointer (null array pointer passed) in cvgetmat, file /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.6.1/modules/core/src/array.cpp, line 2382 libc++abi.dylib: terminate called throwing exception (lldb)
what error , how can fix it?
first should check whether there device @ index 0, this
if (!capture) { // print error , exit cout << "error: capture null!\n"; return -1; }
secondly, :
while ( capture) { frame = cvqueryframe(capture) ; cvshowimage("test", frame); int key = cvwaitkey(1); if ( key == 27 ) break; // esc key pressed }
hope helps
Comments
Post a Comment