由于论文需要,要做一个对比实验,所以就想到这个篇最经典的论文。但从Andrew Davsion下载了matlab的源码。大概看了一下源码,可以运行demo,看到效果。我想跑我现在对比试验的数据集,所以就不得不把自己离线的视频转换为和sequences里的文件相同的属性的图像序列,为.pgm文件,width=320,height=240。图像的尺寸还好理解,但是当看到.pgm后缀的文件就有点晕了。大概查了一下.pgm文件。它是便携式灰度图像格式,在黑白超声图像经常使用。有两种类型p2和p5类型,由文件头和数据两部分构成。所以根据需求就写了一个opencv小程序实现离线视频序列转化为.pgm离散的图像序列。如下:
/--------------------------------------------------------------
//描述:特征法提取关键帧
//IDE:VS2010
//Opencv版本:OPENCV2.4.9
//DATE:20151018
//AUTHOR:create by hu
//--------------------------------------------------------------
#include<cstring>
#include <cv.h>
#include <highgui.h>
#include<iostream>
#include<cxcore.h>
using namespace std;
using namespace cv;
//第一个函数:缩放处理函数
IplImage*doPyrDown(IplImage*in,int filter=IPL_GAUSSIAN_5x5){
assert(in->width%2==0 && in->height%2==0);//确认长宽像素是偶数(否则无法缩放一半)
IplImage* out=cvCreateImage(
cvSize(in->width/2,in->height/2),
in->depth,
in->nChannels
);//创建新图像,长宽各一半,同深度,同通道数
cvPyrDown(in,out);
return(out);
};
int main()
{
CvCapture *capture;
capture = cvCreateFileCapture("test3.avi");
assert(capture!=NULL);
IplImage *frame;
IplImage *out;
cvNamedWindow("Image",1);
int n = 1,m = 412;
char *cstr=new char[20];
while(m--)
{
frame = cvQueryFrame(capture);
out = cvCreateImage(cvSize(frame->width,frame->height),frame->depth,1);
cvCvtColor(frame,out,CV_BGR2GRAY);
out = doPyrDown( out );
if(!out)
break;
sprintf(cstr, "%s%d%s", "tutu\\image", n++, ".pgm");
cvShowImage("Image",out);
cvSaveImage(cstr,out);
/*if(cvWaitKey(66)>=0)
break;*/
}
cvReleaseCapture(&capture);
//cvReleaseImage(&frame);
cvDestroyWindow("Image");
return 0;
}
结果如下图所示: