现在的位置: 首页 > 综合 > 正文

用opencv抽取视频的帧并保存为连续的图片

2013年06月16日 ⁄ 综合 ⁄ 共 626字 ⁄ 字号 评论关闭

#include"stdafx.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
	CvCapture* capture = cvCaptureFromAVI("C:\\me.avi");
	int i = 0;
	IplImage* img = 0;
	char image_name[25];
	cvNamedWindow( "vivi");
	//读取和显示
	while(1)
	{
		img = cvQueryFrame(capture); //获取一帧图片
		if(img == NULL)
			break;

		cvShowImage( "vivi", img ); //将其显示
		char key = cvWaitKey(20);
		sprintf(image_name, "%s%d%s", "..\\tutu\\image", ++i, ".jpg");//保存的图片名
		cvSaveImage( image_name, img);   //保存一帧图片
	}

	cvReleaseCapture(&capture);
	cvDestroyWindow("vivi");
	
	return 0;
}

========================

这里是将抽取的图片保存在了 当前目录下的 tutu 目录下。

开始的时候遇到了   Stack
around the variable was corrupted

的问题。。。

后来才发现是 

存放图片名字的数组 溢出了。。。。

额,要注意哟~~




抱歉!评论已关闭.