latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiLinearRegressionTracking.h 00027 * authors ....: Holger Fillbrandt 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 4.7.2003 00030 * revisions ..: $Id: ltiLinearRegressionTracking.h,v 1.7 2006/02/08 11:23:02 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_LINEAR_REGRESSION_TRACKING_H_ 00034 #define _LTI_LINEAR_REGRESSION_TRACKING_H_ 00035 00036 #include "ltiImage.h" 00037 #include "ltiLinearRegression.h" 00038 00039 namespace lti { 00040 00041 /** 00042 * With this tracking algorithm it is possible to track the movement 00043 * of an object together with scaling and rotation in the image plane. 00044 * It uses the difference between the reference image of the object and 00045 * the image values at the current position to estimate the correction 00046 * of the geometrical parameters. This relation is calculated in a training 00047 * phase using linear regression. To achieve stable tracking results, the 00048 * image values in the background should be similar to those in the 00049 * training image. It is also required that the movement of the object 00050 * between subsequent frames is not too big, there should be still an 00051 * overlap of the object areas at the two positions. 00052 */ 00053 class linearRegressionTracking : public linearRegression<double> { 00054 public: 00055 /** 00056 * the parameters for the class linearRegressionTracking 00057 */ 00058 class parameters : public linearRegression<double>::parameters { 00059 public: 00060 /** 00061 * default constructor 00062 */ 00063 parameters(); 00064 00065 /** 00066 * copy constructor 00067 * @param other the parameters object to be copied 00068 */ 00069 parameters(const parameters& other); 00070 00071 /** 00072 * destructor 00073 */ 00074 ~parameters(); 00075 00076 /** 00077 * returns name of this type 00078 */ 00079 const char* getTypeName() const; 00080 00081 /** 00082 * copy the contents of a parameters object 00083 * @param other the parameters object to be copied 00084 * @return a reference to this parameters object 00085 */ 00086 parameters& copy(const parameters& other); 00087 00088 /** 00089 * copy the contents of a parameters object 00090 * @param other the parameters object to be copied 00091 * @return a reference to this parameters object 00092 */ 00093 parameters& operator=(const parameters& other); 00094 00095 00096 /** 00097 * returns a pointer to a clone of the parameters 00098 */ 00099 virtual functor::parameters* clone() const; 00100 00101 /** 00102 * write the parameters in the given ioHandler 00103 * @param handler the ioHandler to be used 00104 * @param complete if true (the default) the enclosing begin/end will 00105 * be also written, otherwise only the data block will be written. 00106 * @return true if write was successful 00107 */ 00108 virtual bool write(ioHandler& handler,const bool complete=true) const; 00109 00110 /** 00111 * read the parameters from the given ioHandler 00112 * @param handler the ioHandler to be used 00113 * @param complete if true (the default) the enclosing begin/end will 00114 * be also written, otherwise only the data block will be written. 00115 * @return true if write was successful 00116 */ 00117 virtual bool read(ioHandler& handler,const bool complete=true); 00118 00119 # ifdef _LTI_MSC_6 00120 /** 00121 * this function is required by MSVC only, as a workaround for a 00122 * very awful bug, which exists since MSVC V.4.0, and still by 00123 * V.6.0 with all bugfixes (so called "service packs") remains 00124 * there... This method is also public due to another bug, so please 00125 * NEVER EVER call this method directly: use read() instead 00126 */ 00127 bool readMS(ioHandler& handler,const bool complete=true); 00128 00129 /** 00130 * this function is required by MSVC only, as a workaround for a 00131 * very awful bug, which exists since MSVC V.4.0, and still by 00132 * V.6.0 with all bugfixes (so called "service packs") remains 00133 * there... This method is also public due to another bug, so please 00134 * NEVER EVER call this method directly: use write() instead 00135 */ 00136 bool writeMS(ioHandler& handler,const bool complete=true) const; 00137 # endif 00138 00139 // ------------------------------------------------ 00140 // the parameters 00141 // ------------------------------------------------ 00142 00143 00144 /** 00145 * maximum displacement in x-direction to be learned (in pixels) 00146 * default: 10 00147 */ 00148 int maxXDisplace; 00149 00150 /** 00151 * maximum displacement in y-direction to be learned (in pixels) 00152 * default: 10 00153 */ 00154 int maxYDisplace; 00155 00156 /** 00157 * maximum rotation angle to be learned (in rad) 00158 * default: 0.2 00159 */ 00160 float maxAngleDiff; 00161 00162 /** 00163 * maximum scaling difference to be learned 00164 * default: 0.1 00165 */ 00166 float maxScaleDiff; 00167 00168 /** 00169 * size of training set (number of random displacements) 00170 * default: 100 00171 */ 00172 int trainingSize; 00173 00174 00175 }; 00176 00177 /** 00178 * default constructor 00179 */ 00180 linearRegressionTracking(); 00181 00182 /** 00183 * Construct a functor using the given parameters 00184 */ 00185 linearRegressionTracking(const parameters& par); 00186 00187 /** 00188 * copy constructor 00189 * @param other the object to be copied 00190 */ 00191 linearRegressionTracking(const linearRegressionTracking& other); 00192 00193 /** 00194 * destructor 00195 */ 00196 virtual ~linearRegressionTracking(); 00197 00198 /** 00199 * returns the name of this type ("linearRegressionTracking") 00200 */ 00201 virtual const char* getTypeName() const; 00202 00203 /** 00204 * training of x- and y-movement in the image plane using channel values 00205 * @param referenceImage reference channel to be used for training 00206 * @param imageSection rectangle that surrounds the object in the given image 00207 */ 00208 bool learnDisplacement(channel& referenceImage, rectangle imageSection); 00209 00210 /** 00211 * training of x- and y-movement in the image plane using RGB values 00212 * @param referenceImage reference image to be used for training 00213 * @param imageSection rectangle that surrounds the object in the given image 00214 */ 00215 bool learnDisplacementRGB(image& referenceImage, rectangle imageSection); 00216 00217 /** 00218 * estimates the object displacement from the difference of current and reference 00219 * channel values 00220 * @param theImage current frame channel 00221 * @param xpos current x-position of left upper edge of object 00222 * @param ypos current y-position of left upper edge of object 00223 * @param dx estimated displacement in x-direction 00224 * @param dy estimated displacement in y-direction 00225 */ 00226 void getDisplacement(channel& theImage, int xpos, int ypos, double &dx, double &dy) const; 00227 00228 /** 00229 * estimates the object displacement from the difference of current and reference 00230 * RGB values 00231 * @param theImage current frame channel 00232 * @param xpos current x-position of left upper edge of object 00233 * @param ypos current y-position of left upper edge of object 00234 * @param dx estimated displacement in x-direction 00235 * @param dy estimated displacement in y-direction 00236 */ 00237 void getDisplacementRGB(image& theImage, int xpos, int ypos, double &dx, double &dy) const; 00238 00239 /** 00240 * training of x- and y-movement as well as scaling and rotation in the image plane 00241 * using channel values 00242 * @param referenceImage reference channel to be used for training 00243 * @param imageSection rectangle that surrounds the object in the given image 00244 */ 00245 bool learnTracking(channel& referenceImage, rectangle imageSection); 00246 00247 /** 00248 * training of x- and y-movement as well as scaling and rotation in the image plane 00249 * using RGB values 00250 * @param referenceImage reference channel to be used for training 00251 * @param imageSection rectangle that surrounds the object in the given image 00252 */ 00253 bool learnTrackingRGB(image& referenceImage, rectangle imageSection); 00254 00255 /** 00256 * estimates the object displacement, scaling and rotation from the difference of 00257 * current and reference channel values. Use more than one iteration per frame 00258 * for best results. 00259 * @param theImage current frame channel 00260 * @param xpos current x-position of object center 00261 * @param ypos current y-position of object center 00262 * @param alpha current object angle 00263 * @param scale current object scale 00264 * @param dx estimated displacement in x-direction 00265 * @param dy estimated displacement in y-direction 00266 * @param dAlpha estimated angle difference 00267 * @param dScale estimated scale difference 00268 */ 00269 void getDispRotScale(channel& theImage, double xpos, double ypos, double alpha, double scale, double &dx, double &dy, double &dAlpha, double &dScale) const; 00270 00271 /** 00272 * estimates the object displacement, scaling and rotation from the difference of 00273 * current and reference RGB values. Use more than one iteration per frame 00274 * for best results. 00275 * @param theImage current frame image 00276 * @param xpos current x-position of object center 00277 * @param ypos current y-position of object center 00278 * @param alpha current object angle 00279 * @param scale current object scale 00280 * @param dx estimated displacement in x-direction 00281 * @param dy estimated displacement in y-direction 00282 * @param dAlpha estimated angle difference 00283 * @param dScale estimated scale difference 00284 */ 00285 void getDispRotScaleRGB(image& theImage, 00286 double xpos, 00287 double ypos, 00288 double alpha, 00289 double scale, 00290 double &dx, 00291 double &dy, 00292 double &dAlpha, 00293 double &dScale) const; 00294 00295 /** 00296 * copy data of "other" functor. 00297 * @param other the functor to be copied 00298 * @return a reference to this functor object 00299 */ 00300 linearRegressionTracking& copy(const linearRegressionTracking& other); 00301 00302 /** 00303 * alias for copy member 00304 * @param other the functor to be copied 00305 * @return a reference to this functor object 00306 */ 00307 linearRegressionTracking& operator=(const linearRegressionTracking& other); 00308 00309 /** 00310 * returns a pointer to a clone of this functor. 00311 */ 00312 virtual functor* clone() const; 00313 00314 /** 00315 * returns used parameters 00316 */ 00317 const parameters& getParameters() const; 00318 00319 /** 00320 * reads this functor from the given handler. 00321 */ 00322 virtual bool read(ioHandler &handler, const bool complete=true); 00323 00324 /** 00325 * writes this functor to the given handler. 00326 */ 00327 virtual bool write(ioHandler &handler, const bool complete=true) const; 00328 00329 /** 00330 * gets the values of the reference image section used for calculating the error vector 00331 * @param referenceSection contains either the grey-scale or RGB-values in a vector 00332 * @param w width of image section 00333 * @param h height of image section 00334 */ 00335 void getReferenceSection(vector<double> &referenceSection, int &w, int &h) const; 00336 00337 /** 00338 * sets the values of the reference image section used for calculating the error vector 00339 * @param referenceSection contains either the grey-scale or RGB-values in a vector 00340 * @param w width of image section 00341 * @param h height of image section 00342 */ 00343 void setReferenceSection(vector<double> &referenceSection, int w, int h); 00344 00345 00346 // member variables 00347 00348 protected: 00349 /** 00350 * reference image values (grey level or RGB-values subsequently) 00351 * of the image region which shall be tracked 00352 */ 00353 vector<double> referenceValues; 00354 00355 /** 00356 * width and height of the image region 00357 */ 00358 int width, height; 00359 00360 00361 }; 00362 } 00363 00364 #endif