本文主要是介绍利用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结构的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!