latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiHomographyEstimatorBase.h 00027 * authors ....: Claudia Goenner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 25.3.2004 00030 * revisions ..: $Id: ltiHomographyEstimatorBase.h,v 1.8 2006/02/08 11:17:52 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_HOMOGRAPHY_ESTIMATOR_BASE_H_ 00034 #define _LTI_HOMOGRAPHY_ESTIMATOR_BASE_H_ 00035 00036 00037 #include "ltiTransformEstimator.h" 00038 #include "ltiPoint.h" 00039 #include "ltiMatrix.h" 00040 #include "ltiHTypes.h" 00041 00042 namespace lti { 00043 /** 00044 * A parent class for estimating a transform that can be converted to a 00045 * homography. For example all transform estimators, whose result may 00046 * be used by geometricTransform, should be derived from this class. These 00047 * classes must provide an interface to convert their result to hMatrix3D. 00048 * 00049 * The results of all homography estimators can be improved and verified 00050 * by registering the image planes and computing a similarity measure, 00051 * lti::homographyVerification. To allow efficient computations inside 00052 * the homographyVerification, please implement a tranform-method. 00053 * 00054 * The robust estimatorBase performs data normalization on request, whereas 00055 * the derived classes do not. 00056 * 00057 * If you derive a class please remember to support the paramter for 00058 * returning a squared error measure (e.g. squared residual) instead of 00059 * the error (e.g. residual), and thus spare taking the square root. 00060 * 00061 * @see lti::transformEstimator, lti::homography8DOFEstimator 00062 */ 00063 class homographyEstimatorBase : public transformEstimator { 00064 public: 00065 /** 00066 * The parameters for the class homographyEstimatorBase 00067 */ 00068 class parameters : public transformEstimator::parameters { 00069 public: 00070 /** 00071 * Default constructor 00072 */ 00073 parameters(); 00074 00075 /** 00076 * Copy constructor 00077 * @param other the parameters object to be copied 00078 */ 00079 parameters(const parameters& other); 00080 00081 /** 00082 * Destructor 00083 */ 00084 ~parameters(); 00085 00086 /** 00087 * Returns name of this type 00088 */ 00089 const char* getTypeName() const; 00090 00091 /** 00092 * Copy the contents of a parameters object 00093 * @param other the parameters object to be copied 00094 * @return a reference to this parameters object 00095 */ 00096 parameters& copy(const parameters& other); 00097 00098 /** 00099 * Copy the contents of a parameters object 00100 * @param other the parameters object to be copied 00101 * @return a reference to this parameters object 00102 */ 00103 parameters& operator=(const parameters& other); 00104 00105 00106 /** 00107 * Returns a pointer to a clone of the parameters 00108 */ 00109 virtual functor::parameters* clone() const; 00110 00111 /** 00112 * Write the parameters in the given ioHandler 00113 * @param handler the ioHandler to be used 00114 * @param complete if true (the default) the enclosing begin/end will 00115 * be also written, otherwise only the data block will be written. 00116 * @return true if write was successful 00117 */ 00118 virtual bool write(ioHandler& handler,const bool complete=true) const; 00119 00120 /** 00121 * Read the parameters from the given ioHandler 00122 * @param handler the ioHandler to be used 00123 * @param complete if true (the default) the enclosing begin/end will 00124 * be also written, otherwise only the data block will be written. 00125 * @return true if write was successful 00126 */ 00127 virtual bool read(ioHandler& handler,const bool complete=true); 00128 00129 # ifdef _LTI_MSC_6 00130 /** 00131 * This function is required by MSVC only, as a workaround for a 00132 * very awful bug, which exists since MSVC V.4.0, and still by 00133 * V.6.0 with all bugfixes (so called "service packs") remains 00134 * there... This method is also public due to another bug, so please 00135 * NEVER EVER call this method directly: use read() instead 00136 */ 00137 bool readMS(ioHandler& handler,const bool complete=true); 00138 00139 /** 00140 * This function is required by MSVC only, as a workaround for a 00141 * very awful bug, which exists since MSVC V.4.0, and still by 00142 * V.6.0 with all bugfixes (so called "service packs") remains 00143 * there... This method is also public due to another bug, so please 00144 * NEVER EVER call this method directly: use write() instead 00145 */ 00146 bool writeMS(ioHandler& handler,const bool complete=true) const; 00147 # endif 00148 00149 // ------------------------------------------------ 00150 // the parameters 00151 // ------------------------------------------------ 00152 }; 00153 00154 /** 00155 * Default constructor 00156 */ 00157 homographyEstimatorBase(); 00158 00159 /** 00160 * Construct a functor using the given parameters 00161 */ 00162 homographyEstimatorBase(const parameters& par); 00163 00164 /** 00165 * Copy constructor 00166 * @param other the object to be copied 00167 */ 00168 homographyEstimatorBase(const homographyEstimatorBase& other); 00169 00170 /** 00171 * Destructor 00172 */ 00173 virtual ~homographyEstimatorBase(); 00174 00175 /** 00176 * Returns the name of this type ("homographyEstimatorBase") 00177 */ 00178 virtual const char* getTypeName() const; 00179 00180 /** 00181 * Estimates a transform from the supplied point sets, where all 00182 * points are considered. Please implement efficient code using 00183 * iterators here. Not all robust estimators use a random sampling 00184 * approach. Some estimators consider all input points and weight them 00185 * according to their deviation from the transform computed at the prior 00186 * iteration. 00187 * 00188 * All points of one point set give a matrix row, whereas all elements 00189 * of a specifec correspondence stand in a matrix column. 00190 * 00191 * @param src matrix<ipoint> with the point sets. All points of the same 00192 * image stand in a row. The correspondences in another image stand in 00193 * the according columns. 00194 * @param dest fvector the estimated transform. 00195 * @return true if apply successful or false otherwise. 00196 */ 00197 virtual bool apply(const matrix<ipoint>& src, 00198 fvector& dest) const = 0; 00199 00200 /** 00201 * Estimates a transform from the supplied point sets, where all 00202 * points are considered. Usually this method calls the apply without 00203 * the residual first, and then computes the residual. 00204 * 00205 * All points of one point set give a matrix row, whereas all elements 00206 * of a specifec correspondence stand in a matrix column. 00207 * 00208 * @param src matrix<ipoint> with the point sets. All points of the same 00209 * image stand in a row. The correspondences in another image stand in 00210 * the according columns. 00211 * @param dest fvector the estimated transform. 00212 * @param error fvector containing the deviation of each point from the 00213 * estimated transform. Usually this is the residual or 00214 * elementwise squared residual. 00215 * @return true if apply successful or false otherwise. 00216 */ 00217 virtual bool apply(const matrix<ipoint>& src, 00218 fvector& dest, fvector& error) const = 0; 00219 00220 /** 00221 * Estimates a transform from the supplied point sets, whereby only 00222 * the points specified in the index vector are considered. This method 00223 * is used by robost estimators using a monte carlo approach. 00224 * 00225 * All points of one point set give a matrix row, whereas all elements 00226 * of a specifec correspondence stand in a matrix column. 00227 * 00228 * @param src matrix<ipoint> with the point sets. All points of the same 00229 * image stand in a row. The correspondences in another image stand in 00230 * the according columns. 00231 * @param dest fvector the estimated transform. 00232 * @param indices ivector with the indices of the relevant points. 00233 * @param numCorrespondences the first numCorrespondences indices are 00234 * considered. 00235 * @return true if apply successful or false otherwise. 00236 */ 00237 virtual bool apply(const matrix<ipoint>& src, 00238 fvector& dest, 00239 const ivector& indices, 00240 int numCorrespondences) const = 0; 00241 00242 /** 00243 * Estimates a transform from the supplied point sets, whereby only 00244 * the points specified in the index vector are considered. Usually this 00245 * method calls the apply without the residual first, and then computes 00246 * the residual. 00247 * 00248 * All points of one point set give a matrix row, whereas all elements 00249 * of a specifec correspondence stand in a matrix column. 00250 * 00251 * @param src matrix<ipoint> with the point sets. All points of the same 00252 * image stand in a row. The correspondences in another image stand in 00253 * the according columns. 00254 * @param dest fvector the estimated transform. 00255 * @param error fvector containing the deviation of each point from the 00256 * estimated transform. Usually this is the residual or 00257 * elementwise squared residual. 00258 * @param indices ivector with the indices of the relevant points. 00259 * @param numCorrespondences the first numCorrespondences indices are 00260 * considered. 00261 * @return true if apply successful or false otherwise. 00262 */ 00263 virtual bool apply(const matrix<ipoint>& src, 00264 fvector& dest, fvector& error, 00265 const ivector& indices, 00266 int numCorrespondences) const = 0; 00267 00268 /** 00269 * Estimates a homography from the supplied point sets, where all 00270 * points are considered. Please implement efficient code using 00271 * iterators here. Not all robust estimatorBases use a random sampling 00272 * approach. Some estimatorBases consider all input points and weight them 00273 * according to their deviation from the homography computed at the prior 00274 * iteration. 00275 * 00276 * All points of one point set give a matrix row, whereas all elements 00277 * of a specifec correspondence stand in a matrix column. 00278 * 00279 * @param src matrix<fpoint> with the point sets. All points of the same 00280 * image stand in a row. The correspondences in another image stand in 00281 * the according columns. 00282 * @param dest fvector the estimated homography. 00283 * @return true if the homography could be estimated and false otherwise. 00284 */ 00285 virtual bool apply(const matrix<fpoint>& src, 00286 fvector& dest) const = 0; 00287 00288 /** 00289 * Estimates a homography from the supplied point sets, where all 00290 * points are considered. Usually this method calls the apply without 00291 * the residual first, and then computes the residual. 00292 * 00293 * All points of one point set give a matrix row, whereas all elements 00294 * of a specifec correspondence stand in a matrix column. 00295 * 00296 * @param src matrix<fpoint> with the point sets. All points of the same 00297 * image stand in a row. The correspondences in another image 00298 * stand in the according columns. 00299 * @param dest fvector the estimated homography. 00300 * @param error fvector containing the deviation of each point from the 00301 * estimated homography. Usually this is the residual or 00302 * elementwise squared residual. 00303 * @return true if the homography could be estimated and false otherwise. 00304 */ 00305 virtual bool apply(const matrix<fpoint>& src, 00306 fvector& dest, fvector& error) const = 0; 00307 00308 /** 00309 * Estimates a homography from the supplied point sets, whereby only 00310 * the points specified in the index vector are considered. This method 00311 * is used by robost estimatorBases using a monte carlo approach. 00312 * 00313 * All points of one point set give a matrix row, whereas all elements 00314 * of a specifec correspondence stand in a matrix column. 00315 * 00316 * @param src matrix<dpoint> with the point sets. All points of the same 00317 * image stand in a row. The correspondences in another image stand in 00318 * the according columns. 00319 * @param dest fvector the estimated homography. 00320 * @param indices ivector with the indices of the relevant points. 00321 * @param numCorrespondences the first numCorrespondences indices are 00322 * considered. 00323 * @return if the homography could be estimated and false otherwise. 00324 */ 00325 virtual bool apply(const matrix<fpoint>& src, 00326 fvector& dest, 00327 const ivector& indices, 00328 int numCorrespondences) const = 0; 00329 00330 /** 00331 * Estimates a homography from the supplied point sets, whereby only 00332 * the points specified in the index vector are considered. Usually this 00333 * method calls the apply without the residual first, and then computes 00334 * the residual. 00335 * 00336 * All points of one point set give a matrix row, whereas all elements 00337 * of a specifec correspondence stand in a matrix column. 00338 * 00339 * @param src matrix<fpoint> with the point sets. All points of the same 00340 * image stand in a row. The correspondences in another image stand in 00341 * the according columns. 00342 * @param dest fvector the estimated homography. 00343 * @param error fvector containing the deviation of each point from the 00344 * estimated homography. Usually this is the residual or 00345 * elementwise squared residual. All correspondences are 00346 * considered, discarding the valid indices. 00347 * @param indices ivector with the indices of the relevant points. 00348 * @param numCorrespondences the first numCorrespondences indices are 00349 * considered. 00350 * @return true if the homography could be estimated and false otherwise. 00351 */ 00352 virtual bool apply(const matrix<fpoint>& src, 00353 fvector& dest, fvector& error, 00354 const ivector& indices, 00355 int numCorrespondences) const = 0; 00356 00357 /** 00358 * Estimates a homography from the supplied point sets, where all 00359 * points are considered. Please implement efficient code using 00360 * iterators here. Not all robust estimatorBases use a random sampling 00361 * approach. Some estimatorBases consider all input points and weight them 00362 * according to their deviation from the homography computed at the prior 00363 * iteration. 00364 * 00365 * All points of one point set give a matrix row, whereas all elements 00366 * of a specifec correspondence stand in a matrix column. 00367 * 00368 * @param src matrix<dpoint> with the point sets. All points of the same 00369 * image stand in a row. The correspondences in another image stand in 00370 * the according columns. 00371 * @param dest dvector the estimated homography. 00372 * @return true if the homography could be estimated and false otherwise. 00373 */ 00374 virtual bool apply(const matrix<dpoint>& src, 00375 dvector& dest) const = 0; 00376 00377 /** 00378 * Estimates a homography from the supplied point sets, where all 00379 * points are considered. Usually this method calls the apply without 00380 * the residual first, and then computes the residual. 00381 * 00382 * All points of one point set give a matrix row, whereas all elements 00383 * of a specifec correspondence stand in a matrix column. 00384 * 00385 * @param src matrix<dpoint> with the point sets. All points of the same 00386 * image stand in a row. The correspondences in another image stand in 00387 * the according columns. 00388 * @param dest dvector the estimated homography. 00389 * @param error dvector containing the deviation of each point from the 00390 * estimated homography. Usually this is the residual or 00391 * elementwise squared residual. 00392 * @return true if the homography could be estimated and false otherwise. 00393 */ 00394 virtual bool apply(const matrix<dpoint>& src, 00395 dvector& dest, dvector& error) const = 0; 00396 00397 /** 00398 * Estimates a homography from the supplied point sets, whereby only 00399 * the points specified in the index vector are considered. This method 00400 * is used by robost estimatorBases using a monte carlo approach. 00401 * 00402 * All points of one point set give a matrix row, whereas all elements 00403 * of a specifec correspondence stand in a matrix column. 00404 * 00405 * @param src matrix<dpoint> with the point sets. All points of the same 00406 * image stand in a row. The correspondences in another image stand in 00407 * the according columns. 00408 * @param dest dvector the estimated homography. 00409 * @param indices ivector with the indices of the relevant points. 00410 * @param numCorrespondences the first numCorrespondences indices are 00411 * considered. 00412 * @return true if the homography could be estimated and false otherwise. 00413 */ 00414 virtual bool apply(const matrix<dpoint>& src, 00415 dvector& dest, 00416 const ivector& indices, 00417 int numCorrespondences) const = 0; 00418 00419 /** 00420 * Estimates a homography from the supplied point sets, whereby only 00421 * the points specified in the index vector are considered. Usually this 00422 * method calls the apply without the residual first, and then computes 00423 * the residual. 00424 * 00425 * All points of one point set give a matrix row, whereas all elements 00426 * of a specifec correspondence stand in a matrix column. 00427 * 00428 * @param src matrix<dpoint> with the point sets. All points of the same 00429 * image stand in a row. The correspondences in another image stand in 00430 * the according columns. 00431 * @param dest dvector the estimated homography. 00432 * @param error dvector containing the deviation of each point from the 00433 * estimated homography. Usually this is the residual or 00434 * elementwise squared residual. 00435 * @param indices ivector with the indices of the relevant points. 00436 * @param numCorrespondences the first numCorrespondences indices are 00437 * considered. 00438 * @return true if the homography could be estimated and false otherwise. 00439 */ 00440 virtual bool apply(const matrix<dpoint>& src, 00441 dvector& dest, dvector& error, 00442 const ivector& indices, 00443 int numCorrespondences) const = 0; 00444 00445 /** 00446 * Compute the residual for the given correspondences and transformation 00447 * vector. 00448 * @param src matrix<fpoint> with the point sets. All points of the same 00449 * image stand in a row. The correspondences in another image stand in 00450 * the according columns. 00451 * @param transform fvector with the transformation 00452 * @param dest fvector with the residual 00453 * @return true on success and false otherwise. 00454 */ 00455 virtual bool computeResidual(const matrix<fpoint >& src, 00456 const fvector& transform, 00457 fvector& dest) const = 0; 00458 00459 /** 00460 * Compute the residual for the given correspondences and transformation 00461 * vector. 00462 * @param src matrix<dpoint> with the point sets. All points of the same 00463 * image stand in a row. The correspondences in another image stand in 00464 * the according columns. 00465 * @param transform dvector with the transformation 00466 * @param dest dvector with the residual 00467 * @return true on success and false otherwise. 00468 */ 00469 virtual bool computeResidual(const matrix<dpoint >& src, 00470 const dvector& transform, 00471 dvector& dest) const = 0; 00472 00473 /** 00474 * Returns the minimum number of correspondences required to estimate 00475 * the homography. 00476 */ 00477 virtual int minNumberCorrespondences() const = 0; 00478 00479 /** 00480 * Returns the mininum dimension of a correspondence, 00481 * e.g. the minimum dimension of a correspondence pair is 2. 00482 * Each derived homography estimatorBase only works on correspondences of 00483 * priori defined dimensions. 00484 */ 00485 virtual int minCorrespondenceDimension() const = 0; 00486 00487 /** 00488 * Returns the maximum dimension of a correspondence, 00489 * e.g. the maximum dimension of a correspondence pair is 2, whereas 00490 * homographyEstimatorBase running on n-tuples may allow an infinite number. 00491 * Each derived homography estimatorBase only works on correspondences of 00492 * priori defined dimensions. 00493 */ 00494 virtual int maxCorrespondenceDimension() const = 0; 00495 00496 /** 00497 * A transform estimated on normalized data usually differs from 00498 * the transform of the original data. Considering the normalization 00499 * performed this methods computes the transform which applies to the 00500 * original data. 00501 * @param srcdest the normalized transform. The result will be left here 00502 * too. 00503 * @param scale a vector containing the scale applied to each point set. 00504 * @param shift a vector containing the shift of each scaled point set. 00505 */ 00506 bool denormalize(fvector& srcdest, 00507 const vector<fpoint>& scale, 00508 const vector<fpoint>& shift) const = 0; 00509 00510 /** 00511 * A transform estimated on normalized data usually differs from 00512 * the transform of the original data. Considering the normalization 00513 * performed this methods computes the transform which applies to the 00514 * original data. 00515 * @param srcdest the normalized transform. The result will be left here 00516 * too. 00517 * @param scale a vector containing the scale applied to each point set. 00518 * @param shift a vector containing the shift of each scaled point set. 00519 */ 00520 bool denormalize(dvector& srcdest, 00521 const vector<dpoint>& scale, 00522 const vector<dpoint>& shift) const = 0; 00523 00524 /** 00525 * Converts the estimated vector into a hMatrix3D<float>, which is e.g. 00526 * used by geometricTransform. 00527 * @param src fvector the estimated transform. 00528 * @param dest hMatrix3D<float> the estimated transform as a hMatrix3D. 00529 * 00530 * @return true if successful or false otherwise. 00531 */ 00532 virtual bool convert(const fvector& src, hMatrix3D<float>& dest) const = 0; 00533 00534 /** 00535 * Converts the estimated vector into a hMatrix3D<float>, which is e.g. 00536 * used by geometricTransform. 00537 * @param src dvector the estimated transform. 00538 * @param dest hMatrix3D<float> the estimated transform as a hMatrix3D. 00539 * 00540 * @return true if successful or false otherwise. 00541 */ 00542 virtual bool convert(const dvector& src, hMatrix3D<float>& dest) const = 0; 00543 00544 /* Todo ????? 00545 * Converts the estimated vector into a matrix. 00546 * 00547 * @param src fvector the estimated transform. 00548 * @param dest fmatrix the estimated transform as a matrix. 00549 * 00550 * @return true if successful or false otherwise. 00551 */ 00552 //virtual bool convert(const fvector& src, fmatrix& dest) const = 0; 00553 00554 /* Todo ????? 00555 * Converts the estimated vector into a matrix. 00556 * 00557 * @param src dvector the estimated transform. 00558 * @param dest dmatrix the estimated transform as a matrix. 00559 * 00560 * @return true if successful or false otherwise. 00561 */ 00562 //virtual bool convert(const dvector& src, dmatrix& dest) const = 0; 00563 00564 /** 00565 * This is a fast short cut used by the special robust estimator 00566 * homographyVerification in the main loop. 00567 * Please implement this method inline. 00568 * @param pt fpoint the point to be transformed 00569 * @param transf fvector with the transformation, which e.g. was computed 00570 * by an apply. 00571 * @return the transformed point 00572 */ 00573 virtual fpoint transform(const fpoint& pt, 00574 const fvector& transf) const = 0; 00575 00576 /** 00577 * This is a fast short cut used in the special robust estimator 00578 * homographyVerification in the main loop. 00579 * Please implement this method inline. 00580 * @param pt fpoint the point to be transformed 00581 * @param transf fvector with the transformation, which e.g. was computed 00582 * by an apply. 00583 * @return the transformed point 00584 */ 00585 virtual dpoint transform(const dpoint& pt, 00586 const dvector& transf) const = 0; 00587 00588 /** 00589 * Copy data of "other" functor. 00590 * @param other the functor to be copied 00591 * @return a reference to this functor object 00592 */ 00593 homographyEstimatorBase& copy(const homographyEstimatorBase& other); 00594 00595 /** 00596 * Alias for copy member 00597 * @param other the functor to be copied 00598 * @return a reference to this functor object 00599 */ 00600 homographyEstimatorBase& operator=(const homographyEstimatorBase& other); 00601 00602 /** 00603 * Returns a pointer to a clone of this functor. 00604 */ 00605 virtual functor* clone() const = 0; 00606 00607 /** 00608 * Returns used parameters 00609 */ 00610 const parameters& getParameters() const; 00611 00612 }; 00613 } 00614 00615 #endif