39 #include <Matcher2D/TrackerBaseSimple.hh>
40 #include <Base/Image/Image.hh>
41 #include <Base/ImageUtils/ImageDraw.hh>
42 #include <Base/Image/ImageIO.hh>
43 #include <Base/Image/ImageConvert.hh>
44 #include <Base/Geometry/HomgPoint2D.hh>
45 #include <Base/Debug/TimeMeasure.hh>
46 #include <Filter/GradientSobel3x3.hh>
47 #include <Filter/GradientGauss.hh>
48 #include <Filter/GradientGaussAsymmetric.hh>
49 #include <Filter/Binomial.hh>
59 #define StorageType float
62 #define DEFAULT_PARA_FILE_NAME "TrackerBase.ini"
72 BIASERR(
"error loading image "<<name);
77 BIASERR(
"error converting image "<<name);
83 BIASERR(
"error converting image to grey "<<name);
98 unsigned uip[2], radius=1;
99 unsigned char color[]={255,0,0};
107 BIASERR(
"error converting image to unsigned char "<<name);
114 BIASERR(
"error converting image to RGB "<<name);
119 uip[0]=(
unsigned int)rint(p[0]);
120 uip[1]=(
unsigned int)rint(p[1]);
126 double center[2], a[2], b[2], eva, evb;
132 cout << eva<<
", "<<evb<<
"\n";
133 a[0]=na[0]*eva*cov_scale;
134 a[1]=na[1]*eva*cov_scale;
135 b[0]=nb[0]*evb*cov_scale;
136 b[1]=nb[1]*evb*cov_scale;
138 Ellipse(dim, center, a, b, color);
145 cout <<
"wrote "<<file<<endl;
149 int main(
int argc,
char*argv[])
155 KLT_TYPE error, err, residuumMAD, residuumMSD, errorsum=0.0;
158 int newim, oldim, iter;
172 ggaussasymmetric(para);
173 int *gradienttype = AddGradientType(para);
180 if (argc-argind<4 || argind<1){
181 cerr << argv[0] <<
" : <x-coo> <y-coo> <image> <image> ..."<< endl;
192 switch (*gradienttype){
199 cerr <<
"GradientGauss\n";
202 grad = &ggaussasymmetric;
203 cerr <<
"GradientGaussAsymmetric\n";
206 BIASERR(
"unknown gradient type");
216 p[0][0]=atof(argv[argind]);
217 p[0][1]=atof(argv[argind+1]);
218 cout <<
"attempt to track point "<<p[0] << endl;
222 if (LoadImage(argv[argind+2], im[0])!=0){
223 BIASERR(
"error loading image "<<argv[argind+2]);
228 binomial.Filter3x3(im[0], fim[0]);
229 grad->Filter(fim[0], gradx[0], grady[0]);
235 while (counter < argc-1){
237 newim=(newim==0)?(1):(0);
238 oldim=(newim==0)?(1):(0);
240 if (LoadImage(argv[counter], im[newim])!=0){
241 BIASERR(
"error loading image "<<argv[counter]);
245 cout <<
"\n------- newim: " << argv[counter]
246 <<
"\n------- oldim: " << argv[counter-1] << endl;
251 if (debug) cerr << appdata.
stag <<
" : "<<appdata.
sdata<<endl;
252 sscanf(appdata.
sdata.c_str(),
"[ %lf %lf %lf ]",
253 &realpoint[0], &realpoint[1], &realpoint[2]);
257 if (debug) cerr <<
"realpoint is at "<<realpoint<<endl;
259 BIASERR(
"cannot find HomgPoint2D in meta data");
264 binomial.Filter3x3(im[newim], fim[newim]);
265 grad->Filter(fim[newim], gradx[newim], grady[newim]);
288 cerr <<
"Tracking from "<<p[oldim]<<
" --> "<<p[oldim]<<endl;
292 tracker->
Init(fim[oldim], fim[newim], gradx[oldim], grady[oldim],
293 gradx[newim], grady[newim]);
297 tracker->
Track(p[oldim], p[oldim], p[newim], error, iter,
298 residuumMAD, residuumMSD, cov);
311 cout <<
"point ("<<p[oldim][0]<<
", "<<p[oldim][1]<<
") too close to "
312 <<
"image border, stopping"<<endl;
315 BIASERR(
"error matching "<<res);
320 err=sqrt((p[newim][0]-realpoint[0])*(p[newim][0]-realpoint[0])+
321 (p[newim][1]-realpoint[1])*(p[newim][1]-realpoint[1]));
326 Draw(im[newim], p[newim], cov, argv[counter]);
328 cout << setw(2) << counter-3 <<
" : (" << p[oldim][0]<<
", "<<p[oldim][1]
329 <<
") -> ("<< p[newim][0]<<
", "<<p[newim][1]<<
") klt-error: "<<error
330 <<
" real: ("<<realpoint[0]<<
", "<<realpoint[1]
331 <<
") dist-err: "<<err<<
" residuumMAD: "<<residuumMAD
332 <<
" residuumMSD: "<<residuumMSD<<endl;
336 cerr <<
"errorsum over "<<counter-3<<
" images: "<<errorsum<<endl
337 <<
" mean error "<<errorsum/(double)(counter-3)<<endl;
340 cerr <<
"KLT trackin over "<<argc-3<<
" images took "<<timer.
GetRealTime()
342 <<
"\n this is equal to "<<timer.
GetRealTime()/double(argc-3)
343 <<
" us per image and corner" << endl;
void Print(std::ostream &os=std::cout) const
std::string stag
the tag as given in ascii meta data
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn't change the ...
gradient calculation with separated gauss masks
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
int UpdateParameter(int &argc, char *argv[], const std::string &default_filename)
update all arguments from command line and parameter file
void Init(Image< StorageType > &im1, Image< StorageType > &im2, Image< StorageType > &gradx1, Image< StorageType > &grady1, Image< StorageType > &gradx2, Image< StorageType > &grady2)
Prepare for tracking with prefiltered images.
Base class for the different tracking algorithms, defining the interfaces for the tracking functions...
base class for simple n->2n filter implementations
void DisableDestructorWarning()
Uses this just before end of your program to avoid error from destructor.
static int CircleCenterFilled(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[])
draws a filled circle using Value
int length
number of bytes used by the data block
gradient calculation with sobel 3 by 3 masks
std::string sdata
the data as given in ascii meta data
char * data
pointer to block of data
int Track(HomgPoint2D &p1, HomgPoint2D &p2, HomgPoint2D &p2tracked, KLT_TYPE &error, int &iter, KLT_TYPE &residuumMAD, KLT_TYPE &residuumMSD, Matrix< KLT_TYPE > &cov, const Matrix2x2< KLT_TYPE > &AffinePred=Matrix2x2< KLT_TYPE >(MatrixIdentity), Matrix2x2< KLT_TYPE > *AffineResult=NULL)
Calculates correspondence from image1 to image2.
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
static int Ellipse(Image< StorageType > &im, double center[2], double a[2], double b[2], const StorageType Value[])
draws an ellipse at center with half axes a and b
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
The image template class for specific storage types.
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.
enum TAppData tag
The tag defines the type of data, e.g.
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
gradient calculation with separated gauss masks
int EigenvalueDecomposition(T &value1, Vector2< T > &vector1, T &value2, Vector2< T > &vector2) const
Eigenvalue decomposition.
enum EColorModel GetColorModel() const
This class Param provides generic support for parameters.
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...
(8bit) unsigned char image storage type
void SetWriteOptions(bool indent, bool comments, bool enhanced)
void SetMetaData(const MetaData &m)
This is the base class for images in BIAS.
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
binomial low pass filter class
class TimeMeasure contains functions for timing real time and cpu time.
this is a chunk of metadata, also see MetaData
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey