#include <Matcher2D/RegionMatcher.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Filter/GradientSobel3x3.hh>
#include <Base/Math/Random.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace BIAS;
using namespace std;
#define InST float
#define OutST float
int main(int argc, char*argv[])
{
unsigned int p1[2], start[2], end[2];
unsigned int halfwinsize=7;
unsigned int epsilon=2;
double gradientscale=0.5;
unsigned int result[2];
double correlation=-1.0;
unsigned int offset=epsilon+halfwinsize;
int grad_threshold=2;
int res;
bool UseSAD=false;
double length1, length2;
int count = 10000;
int maxlength, maxlength2;
bool debug=false;
int debuglevel=0;
if (argc<2){
cerr << argv[0] << " : <image> ..."<< endl;
return -5;
}
BIASERR("error loading image "<<argv[1]);
return -1;
}
im1=inputUC;
im2=im1;
grad2=grad1;
BIASERR("error writing image grad.mip");
return -1;
}
for (int i=0; i< count; i++){
do{
if (debuglevel>=2)
cout << i<<":\tp1: "<<p1[0]<<" "<<p1[1]<<endl;
maxlength=
((int)p1[0]-(
int)offset>(int)im1.
GetWidth()-(int)offset-(
int)p1[0]-1) ?
(
int)im1.
GetWidth()-(int)offset-(
int)p1[0]-1 : (int)p1[0]-(
int)offset ;
maxlength2=
((int)p1[1]-(
int)offset>(int)im1.
GetHeight()-(int)offset-(
int)p1[1]-1) ?
(
int)im1.
GetHeight()-(int)offset-(
int)p1[1]-1 : (int)p1[1]-(
int)offset ;
maxlength=(maxlength>maxlength2)?maxlength2:maxlength;
if (debuglevel>=2)
cout << "p1: "<<p1[0]<<" "<<p1[1]<<"\tmaxlength: "<<maxlength<<endl;
start[0]=(unsigned int)rint((int)p1[0]+sin(angle)*length1);
start[1]=(unsigned int)rint((int)p1[1]+cos(angle)*length1);
end[0]=(unsigned int)rint((int)p1[0]-sin(angle)*length2);
end[1]=(unsigned int)rint((int)p1[1]-cos(angle)*length2);
if (debuglevel>=2)
cout << "searching between "
<<start[0]<<" "<<start[1]<<" and "<<end[0]<<" "<<end[1]<<endl;
int mycount=1;
for (int k=0; k<mycount; k++){
p1, start, end,
halfwinsize,
epsilon, gradientscale, result,
correlation)
!=0)
{
BIASERR("error in LineMatcherNCC");
return -2;
};
}
cout <<
"SAD took "<<timerSAD.
GetUserTime()/mycount<<
" ms"<<endl;
for (int k=0; k<mycount; k++){
epsilon, gradientscale, result,
correlation)!=0){
BIASERR("error in LineMatcherNCC");
return -2;
};
}
cout <<
"NCC took "<<timerNCC.
GetUserTime()/mycount<<
" ms"<<endl;
if (debuglevel>=1)
cout << "correspondence to "<<p1[0]<<" "<<p1[1]<<" searched between "
<<start[0]<<" "<<start[1]<<" and "<<end[0]<<" "<<end[1]<<" is at "
<<result[0]<<" "<<result[1]<<" with correlation "<<correlation
<<endl;
if ((result[0]!=p1[0])||(result[1]!=p1[1])){
cerr << "\n\n***********\n\nerror, found wrong result\n\n***********\n\n"<<endl;
debug=true;
} else {
if (UseSAD){
if (correlation>0.1) debug=true;
else debug=false;
} else {
if (correlation<1.0) debug=true;
else debug = false;
}
}
if (debug){
cerr << "staring debug: "<<endl;
if (UseSAD){
halfwinsize,
epsilon, gradientscale, result,
correlation))!=0){
BIASERR("error in LineMatcherSAD "<<res);
};
} else {
halfwinsize,
epsilon, gradientscale, result,
correlation))!=0){
BIASERR("error in LineMatcherNCC "<<res);
};
}
}
};
cout <<
"sum NCC took "<<timerNCC.
GetUserTime()<<
" ms"<<endl
<<
"sum SAD took "<<timerSAD.
GetUserTime()<<
" ms"<<endl;
return 0;
}