利用OpenCv读取视频时释放IplImage结构的问题


1.利用OpenCv读取视频
注意:下面的cvCreateFileCapture()和cvCreateImage()函数需要释放!且不要出现在while()循环里面
 
  

int main()
{
	string video_dir = "F:\\监控视频\\1.mp4";
	CvCapture *capture = NULL;
	IplImage *frame = NULL;
	IplImage* temp = NULL;
	IplImage *dst = NULL;
	capture = cvCreateFileCapture(video_dir.c_str());//最后要cvReleaseCapture(&capture);

	int src_frame_width = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);//获取视频的宽
	int src_frame_height = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);//获取视频的高
	CvSize size;
	size.width = src_frame_width; 
	size.height = src_frame_height;

	temp = cvCreateImage(size, IPL_DEPTH_8U, 1);//创建目标图像
	CvSize dstSize = cvSize(temp->width / 8, temp->height / 8);
	dst = cvCreateImage(dstSize, temp->depth, temp->nChannels);
        while (1)
	{
		frame = cvQueryFrame(capture);
		cvCvtColor(frame, temp, CV_BGR2GRAY);//cvCvtColor(src,des,CV_BGR2GRAY)  
		cvResize(temp, dst, CV_INTER_LINEAR);
		
		cvNamedWindow("video");
		cvShowImage("video", dst);
		cvWaitKey(1);
	}
	cvReleaseCapture(&capture);
	cvReleaseImage(&dst);
	cvDestroyAllWindows();
	return 0;
}

你可能感兴趣的:(利用OpenCv读取视频时释放IplImage结构的问题)