int main(int argc, char* argv[]) {
ofstream file;
file.open("Motion.dat");
int frame_number = 0;
CvCapture* capture = cvCreateFileCapture("Cricketc1.avi");
CvCapture* capture1 = cvCreateFileCapture("Cricketc1.avi");
IplImage* imgsize = NULL;
IplImage *img1 = NULL;
IplImage *img2 = NULL;
IplImage *vidFrame = NULL;
IplImage *imggray1 = NULL;
IplImage *imggray2 = NULL;
IplImage *imggray3 = NULL;
cvNamedWindow("Video", 0);
cvNamedWindow("Video1", 0);
imgsize = cvQueryFrame(capture1);
assert(imgsize);
CvSize sz = cvGetSize(imgsize);
cvReleaseCapture(&capture1);
imggray1 = cvCreateImage(sz, IPL_DEPTH_8U, 1);
imggray2 = cvCreateImage(sz, IPL_DEPTH_8U, 1);
imggray3 = cvCreateImage(sz, IPL_DEPTH_8U, 1);
while (true) {
frame_number++;
img1 = cvQueryFrame(capture);
if(img1->imageData == NULL)
break;
cvCvtColor(img1, imggray1, CV_RGB2GRAY);
img2 = cvQueryFrame(capture);
if(img2->imageData == NULL)
break;
cvCvtColor(img1, imggray1, CV_RGB2GRAY);
cvAbsDiff( imggray1, imggray2, imggray3 );
CvScalar sumDiff = cvSum (imggray3);
cout << sunDiff.val[0] << sunDiff.val[1] << sunDiff.val[2] << endl;
cvWaitKey(40);
}
cvReleaseCapture(&capture);
cvDestroyAllWindows();
file.close();
system("Pause");
return 0;
}
@ 25 fps 的视频共有 1251 帧。
但循环在frame_number
等于 625 处中断,在 line if(img2->imageData == NULL)
。
如果我在 while 循环之间进行任何计算,则主要会出现此错误。一个简单的 cvShowImage() 可以正常工作,但任何其他操作都会导致此错误出现。
这是之后出现的错误:
Unhandled exception at 0x00221de7 in getMotion2.exe: 0xC0000005: Access violation reading location 0x00000044.
问题是什么 ?