#include <cv.h>
#include <highgui.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
//定义文件夹下视频的数量
#define NumVideo 4
#define WidthResize 300
#define HeightResize 180
int main()
{
CvSize size;
FILE *fp;
if((fp=fopen("..\\dstAbsGray.txt","w"))==NULL)
{
printf("can not open the neuron file\n");
exit(0);
}
//初始化一个视频文件捕捉器
char *video_name = NULL;
CvCapture* capture;
video_name = (char*)malloc(50*sizeof(char)); //动态分配内存
for(int jj=1; jj<=NumVideo; jj++)
{
int i=0; //视频读取标志标志
printf("\n第%d段视频\n",jj);
sprintf_s(video_name, 50, "..\\video\\%d.avi",jj);//保存的图片名
capture = cvCaptureFromAVI(video_name);
//
CvCapture* capture = cvCaptureFromAVI("..\\video\\4.avi");
if( capture == NULL )
{
printf("视频文件打开失败!!");
continue;
}
int frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
printf("\tvideo height : %d\n\tvideo width : %d\n\tfps : %d\n\tframe numbers : %d\n", frameH, frameW, fps, numFrames);
//定义和初始化变量
IplImage* image = NULL;
image = cvQueryFrame(capture); //获取一帧图片
if(image == NULL)
{
printf("视频文件第一帧打开失败!!");
continue;
}
cvNamedWindow("原始视频");
cvShowImage( "原始视频", image );
size.width = WidthResize;
size.height = HeightResize;
IplImage* desc = cvCreateImage(size,image->depth,image->nChannels);
//
cvResize(imageTemp,desc,CV_INTER_CUBIC);
cvResize(image,desc,CV_INTER_CUBIC);
if(desc == NULL)
{
printf("视频文件Resize失败!!");
continue;
}
IplImage* temp = cvCloneImage( desc );
cvNamedWindow("Box Example");
cvShowImage( "Box Example", temp );
char * image_name=NULL;
//char image_name[20];
image_name=(char *)malloc(50*sizeof(char)); //动态分配内存
int c = 0;
while( 1 )
{
//获取空格键值,并置位抠图标志位flag
c = cvWaitKey(1);
//
if((char)c==(char)32)
{
printf("%d\n",i);
image = cvQueryFrame(capture); //获取一帧图片
if( capture == NULL )
{
printf("视频文件打开失败!!");
continue;
}
cvNamedWindow("原始视频");
cvShowImage( "原始视频", image );
sprintf_s(image_name,50, "%s%d%s%d%s", "..\\sourceImage\\", jj,"_",++i, ".jpg");//保存的图片名
//如何将这些图片保存到一个指定的文件夹中? //"d:\\images\\image" 将图片存放在d盘images文件夹下
cvSaveImage(image_name, image); //保存一帧图片
}
if(i == numFrames - 1)
break;
}
}
}