问题描述
- 返回时C++内存问题opencv写的
-
//读取摄像头并保存为AVI文件#include "cv.h"
#include "highgui.h"int main(int argc,char**argv)
{
CvCapture* capture=0;
IplImage *bgr_frame;
int fps=25;
int i;
CvSize size;
CvVideoWriter *writer;
cvNamedWindow("Jimmy",CV_WINDOW_AUTOSIZE);//从摄像头读取视频 if(argc==1) { capture=cvCreateCameraCapture(0); } else { capture=cvCreateFileCapture(argv[1]); } assert(capture!=NULL); size=cvSize((int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT)); writer=cvCreateVideoWriter("out.avi",CV_FOURCC('F','L','V','1'),fps,size,1); //视频存磁盘 for(i=1;i<=100;i++) { bgr_frame=cvQueryFrame(capture); cvWriteFrame(writer,bgr_frame); cvShowImage("Jimmy",bgr_frame); cvWaitKey(1000/fps); } cvReleaseVideoWriter(&writer); cvReleaseImage(&bgr_frame); cvReleaseCapture(&capture); cvDestroyWindow("Jimmy"); return 0;
}
这个程序能正常执行,但是返回时会报错,我内存都释放了,实在不知道错在哪
Unhandled exception at 0x7656c42d in hw.exe: Microsoft C++ exception: cv::Exception at memory location 0x0033f7f0..
解决方案
断点调试一下,看出错的callstack
时间: 2024-11-17 18:56:21