32 #include <Matcher2D/RegionMatcher.hh>
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Image/ImageConvert.hh>
39 #include <Filter/GradientSobel3x3.hh>
41 #include <Base/Math/Random.hh>
42 #include <Base/Debug/TimeMeasure.hh>
61 int main(
int argc,
char*argv[])
67 unsigned int p1[2], start[2], end[2];
68 unsigned int halfwinsize=7;
69 unsigned int epsilon=2;
70 double gradientscale=0.5;
71 unsigned int result[2];
72 double correlation=-1.0;
73 unsigned int offset=epsilon+halfwinsize;
86 double length1, length2;
88 int maxlength, maxlength2;
94 cerr << argv[0] <<
" : <image> ..."<< endl;
99 BIASERR(
"error loading image "<<argv[1]);
113 BIASERR(
"error writing image grad.mip");
117 for (
int i=0; i< count; i++){
127 cout << i<<
":\tp1: "<<p1[0]<<
" "<<p1[1]<<endl;
129 ((int)p1[0]-(
int)offset>(int)im1.
GetWidth()-(int)offset-(
int)p1[0]-1) ?
130 (
int)im1.
GetWidth()-(int)offset-(
int)p1[0]-1 : (int)p1[0]-(
int)offset ;
132 ((int)p1[1]-(
int)offset>(int)im1.
GetHeight()-(int)offset-(
int)p1[1]-1) ?
133 (
int)im1.
GetHeight()-(int)offset-(
int)p1[1]-1 : (int)p1[1]-(
int)offset ;
134 maxlength=(maxlength>maxlength2)?maxlength2:maxlength;
136 cout <<
"p1: "<<p1[0]<<
" "<<p1[1]<<
"\tmaxlength: "<<maxlength<<endl;
138 start[0]=(
unsigned int)rint((
int)p1[0]+sin(angle)*length1);
139 start[1]=(
unsigned int)rint((
int)p1[1]+cos(angle)*length1);
141 end[0]=(
unsigned int)rint((
int)p1[0]-sin(angle)*length2);
142 end[1]=(
unsigned int)rint((
int)p1[1]-cos(angle)*length2);
145 cout <<
"searching between "
146 <<start[0]<<
" "<<start[1]<<
" and "<<end[0]<<
" "<<end[1]<<endl;
151 for (
int k=0; k<mycount; k++){
159 epsilon, gradientscale, result,
163 BIASERR(
"error in LineMatcherNCC");
168 cout <<
"SAD took "<<timerSAD.
GetUserTime()/mycount<<
" ms"<<endl;
171 for (
int k=0; k<mycount; k++){
177 epsilon, gradientscale, result,
179 BIASERR(
"error in LineMatcherNCC");
184 cout <<
"NCC took "<<timerNCC.
GetUserTime()/mycount<<
" ms"<<endl;
188 cout <<
"correspondence to "<<p1[0]<<
" "<<p1[1]<<
" searched between "
189 <<start[0]<<
" "<<start[1]<<
" and "<<end[0]<<
" "<<end[1]<<
" is at "
190 <<result[0]<<
" "<<result[1]<<
" with correlation "<<correlation
193 if ((result[0]!=p1[0])||(result[1]!=p1[1])){
194 cerr <<
"\n\n***********\n\nerror, found wrong result\n\n***********\n\n"<<endl;
198 if (correlation>0.1) debug=
true;
201 if (correlation<1.0) debug=
true;
206 cerr <<
"staring debug: "<<endl;
215 epsilon, gradientscale, result,
217 BIASERR(
"error in LineMatcherSAD "<<res);
226 epsilon, gradientscale, result,
228 BIASERR(
"error in LineMatcherNCC "<<res);
236 cout <<
"sum NCC took "<<timerNCC.
GetUserTime()<<
" ms"<<endl
237 <<
"sum SAD took "<<timerSAD.
GetUserTime()<<
" ms"<<endl;
int LineMatcherSAD(const unsigned int p1[2], const unsigned int start2[2], const unsigned int end2[2], const StorageType **ida1, const StorageType **ida2, const StorageType **grad1, const StorageType **grad2, const unsigned int halfwinsize, const unsigned int epsilon, const double gradientscale, unsigned int result[2], double &sad) const
as above but uses SAD
gradient calculation with sobel 3 by 3 masks
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
unsigned int GetWidth() const
int GetUniformDistributedInt(const int min, const int max)
get uniform distributed random variable including min/max
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
void SetDebugLevel(const long int lv)
unsigned int GetHeight() const
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Basic functions for CornerMatcher.
int LineMatcherNCC(const unsigned int p1[2], const unsigned int start2[2], const unsigned int end2[2], const StorageType **ida1, const StorageType **ida2, const StorageType **grad1, const StorageType **grad2, const unsigned int halfwinsize, const unsigned int epsilon, const double gradientscale, unsigned int result[2], double &correlation) const
find correspondence to p1 from ida1 in ida2 at aproximate starting position p2 using KLT ...
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy
double GetUserTime() const
return user time (=system usage time) in msec JW For Win32: user-time is the sum over all processes o...
class for producing random numbers from different distributions
class TimeMeasure contains functions for timing real time and cpu time.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase