Thursday, June 10, 2004

Read a bunch of images

Just like read image from "frame0.bmp" to "frame99.bmp".
strcpy(filename,"C:\\Data\\OpticalFlow\\HS\\testOF\\img\\frame#.bmp");
result=fileindex(filename,glbnframe,filereturn1);
glbnframe++;
k = OpticalFlow_HS( output, flowx1, flowy1, flowx2, flowy2,filereturn1, filereturn2, lambda, num_iter);


Need to add the following two functions to implement the above:
#include
/** decompose path/filename string ********************************/
short decomposeslp(char *namein,char *spath,char *outprefix,char *midterm,char *suffix)
{
char period,pound,btemp,bslash,colon;
int Nstr,Npound,Nperiod,Npath,n;
period='.';
pound='#';
bslash='\\';
colon=':';
/* determine prefix and suffix of output file */
Nstr=strlen(namein);
if(Nstr==0) goto SKIP;
Npath=Npound=Nperiod=-1;
for(n=0;n {
btemp=*(namein+n);
if((btemp==bslash)||(btemp==colon)) {Npath=n;}
if(btemp==pound) {Npound=n;}
if(btemp==period) {Nperiod=n;}
}
if((Nperiod>=0)&&(Npound>=0))
{
if(Nperiod }
if((Npath>=0)&&(Npound>=0))
{
if(Npath>Npound) Npound=-1;
}
if((Nperiod>=0)&&(Npath>=0))
{
if(Nperiod }
*spath=*outprefix=*midterm=*suffix='\0';
/*. store path .*/
for(n=0;n<=Npath;n++) *(spath+n)=*(namein+n);
*(spath+Npath+1)='\0';
if(Npound>=0)
{
/*. store outprefix .*/
for(n=Npath+1;n *(outprefix+Npound-(Npath+1))='\0';
}
else
{
if(Nperiod>=0)
{
/*. store outprefix .*/
for(n=Npath+1;n *(outprefix+Nperiod-(Npath+1))='\0';
}
else
{
/*. store outprefix .*/
for(n=Npath+1;n *(outprefix+Nstr-(Npath+1))='\0';
}
}
if(Npound>=0)
{
if(Nperiod>=0)
{
/*. store midterm .*/
for(n=Npound+1;n *(midterm+Nperiod-(Npound+1))='\0';
}
else
{
/*. store midterm .*/
for(n=Npound+1;n *(midterm+Nstr-(Npound+1))='\0';
}
}
if(Nperiod>=0)
{
/*. store suffix .*/
for(n=Nperiod+1;n *(suffix+Nstr-(Nperiod+1))='\0';
}
else *suffix='\0';
SKIP:;
if(Npound>=0) return(1);
else return(0);
}

short fileindex(char *filename,long inum,char *filereturn)
{
short isingle;
char spathl[255],sprefixl[255],smidterml[255],suffixl[255];
short Ipoundinl;
//decompose file name
Ipoundinl=decomposeslp(filename,spathl,sprefixl,smidterml,suffixl);
// construct proper file name
if(Ipoundinl!=0) sprintf(filereturn,"%s%s%ld%s.%s",spathl,sprefixl,inum,smidterml,suffixl);
else strcpy(filereturn,filename);
if(Ipoundinl!=0) isingle=0;
else isingle=1;
return(isingle);
}

void plot_crosshairs(IplImage *image, CvPoint *point,
int size=15, double color=CV_RGB(255,0,0),
int thickness=1) {
/* Show some simple crosshairs on an image at the given point */
CvPoint endpoint1, endpoint2;
endpoint1.x = point->x - size/2;
endpoint1.y = point->y;
endpoint2.x = point->x + size/2;
endpoint2.y = point->y;
cvLine(image, endpoint1, endpoint2, color, thickness);
endpoint1.y = point->y - size/2;
endpoint1.x = point->x;
endpoint2.y = point->y + size/2;
endpoint2.x = point->x;
cvLine(image, endpoint1, endpoint2, color, thickness);
}

No comments:

Post a Comment