I’m new to opencv, and write an very simple program to display the images captured from camera.
The code is:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
cvNamedWindow("win");
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame = cvQueryFrame(capture);
IplImage* out = cvCreateImage(cvGetSize(frame), frame->depth, 1);
while(1) {
frame = cvQueryFrame(capture);
if(!frame) break;
cvCanny(frame, out, 10, 100, 30);
cvShowImage("win", out); // !!!!! this line thrown exception
char c = cvWaitKey(20);
if(c==27) break;
}
cvReleaseImage(&out);
cvReleaseCapture(&capture);
cvDestroyWindow("win");
return 0;
}
But when I run it, it throws exception:
Unhandled exception at at 0x000007FEFDD0CACD in Project2.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000024DA50.
Where is wrong, and how to fix it?
Update
At last, I found the reason:
cvCanny(frame, out, 10, 100, 30);
The last argument is too big, if I change it to 3, everything works fine.
Never used opencv before, but I’m going to take a guess here that one of the following:
is NULL or invalid, and since you are then passing them onto other functions you are getting crashes further on.