I’m going to run this really simple cod that will be compiled in visual studio and opencv libraries are used in.
#include <opencv2/opencv.hpp>
int main()
{
CvCapture *capture=cvCaptureFromFile("sample_1.avi");
IplImage *FirstFrame=cvQueryFrame(capture);
cvShowImage("first",FirstFrame);
cvWaitKey();
}
The compile process is OK But when debugger reaches
IplImage *FirstFrame=cvQueryFrame(capture);
the following exception is ocurred :
Unhandled exception at 0x715f6a7e in VideoTest.exe: 0xC0000005: Access violation reading location 0x01bc4000.
How can I fix this problem ?
Thanks!
cvQueryFrame()crashes becausecvCaptureFromFile()is probably failing. That happens when it can’t open/find the file or when OpenCV doesn’t support the container/codec of the video.Whenever a function returns something is good practice to test the validity of what was returned, in this case since it’s a pointer you should do: