#include <Matcher2D/CornerMatcher.hh>
#include <Base/Image/Image.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Geometry/HomgPoint2D.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Filter/Gradient.hh>
#include <iostream>
#include <iomanip>
using namespace BIAS;
using namespace std;
int main(int argc, char*argv[])
{
double correlation, mincorrelation=1.0, error, errorsum=0.0;
unsigned int halfsearchwinsize=2;
unsigned int uip[2], rectsize=7;
unsigned int halfnccwinsize=3;
unsigned int newim, oldim, res;
int counter;
bool debug=false;
string file;
bool draw=false;
bool UseLeastSquaresParabola=false;
if (debug){
}
if (argc<4){
cerr << argv[0] << " : <x-coo> <y-coo> <image> <image> ..."<< endl;
return -5;
}
p[0][0]=atof(argv[1]);
p[0][1]=atof(argv[2]);
p[0][2]=p[1][2]=1.0;
BIASERR("error loading image "<<argv[3]);
return -1;
}
counter=3;
newim=0;
while (counter < argc-1){
counter++;
newim=(newim==0)?(1):(0);
oldim=(newim==0)?(1):(0);
BIASERR("error loading image "<<argv[counter]);
return -1;
} else {
if (debug)
cout << "--------------- newim: " << argv[counter]
<< " --- oldim: " << argv[counter-1] << endl;
if (debug) cerr << appdata.
stag <<
" : "<<appdata.
sdata<<endl;
sscanf(appdata.
sdata.c_str(),
"[ %lf %lf %lf ]",
&realpoint[0], &realpoint[1], &realpoint[2]);
} else {
}
if (debug) cerr <<"realpoint is at "<<realpoint<<endl;
} else {
BIASERR("cannot find HomgPoint2D in meta data");
}
}
if (p[oldim][0]<=halfnccwinsize+3 ||
p[oldim][1]<=halfnccwinsize+3 ||
p[oldim][0]+halfnccwinsize+3>=im[oldim].GetWidth()-1 ||
p[oldim][1]+halfnccwinsize+3>=im[oldim].GetHeight()-1){
cout << "point ("<<p[oldim][0]<<", "<<p[oldim][1]<<") too close to "
<<"image border, stopping"<<endl;
break;
}
if ((res=matcher.
NCCSearch(p[oldim], p[oldim], im[oldim], im[newim],
halfnccwinsize, halfsearchwinsize, p[newim],
mincorrelation, correlation))!=0){
BIASERR("error in NCCSearch");
}
if (res!=0){
BIASERR("error matching");
break;
}
if (debug)
cerr << p[oldim] << " NCC -> " << p[newim]
<< " ("<<correlation<<") Parabola -> ";
if (UseLeastSquaresParabola){
if ((res=matcher.
ParabolaNCC5(p[oldim], p[newim], im[oldim], im[newim],
halfnccwinsize, p[newim]))!=0){
BIASERR("error in ParabolaNCC");
break;
}
} else {
if ((res=matcher.
ParabolaNCC(p[oldim], p[newim], im[oldim], im[newim],
halfnccwinsize, p[newim]))!=0){
BIASERR("error in ParabolaNCC");
break;
}
}
if (debug)
cerr << p[newim] << endl;
if (res!=0){
BIASERR("error matching");
break;
}
errorsum+=error;
cout << setw(2) << counter-3 << " : (" << p[oldim][0]<<", "<<p[oldim][1]
<< ") -> ("<< p[newim][0]<<", "<<p[newim][1]<<") corr: "<<correlation
<<" real: ("<<realpoint[0]<<", "<<realpoint[1]
<<") error: "<<error<<endl;
if (draw){
uip[0]=(unsigned int)rint(p[newim][0]);
uip[1]=(unsigned int)rint(p[newim][1]);
drawim=im[newim];
file=argv[counter];
file+=".tracked";
}
}
cerr <<"errorsum over "<<counter-3<<" images: "<<errorsum<<endl
<<" mean error "<<errorsum/(double)(counter-3)<<endl;
cerr << "Parabola approximation over "<<argc-3<<" images took "
<<
"\n this is equal to "<<timer.
GetUserTime()/double(argc-3)
<<" ms per image and corner" << endl;
return 0;
}