last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2008 00003 * Pablo Alvarado 00004 * 00005 * This file is part of the Computer Vision and Robotic Library (CVR-Lib) 00006 * 00007 * The CVR-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the BSD License. 00009 * 00010 * All rights reserved. 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted provided that the following conditions are met: 00014 * 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 00022 * 3. Neither the name of the authors nor the names of its contributors may be 00023 * used to endorse or promote products derived from this software without 00024 * specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 * POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 00039 /** 00040 * \file cvrLocationMatch.h 00041 * Contains the class cvr::locationMatch, 00042 * which has still to be documented by Pablo Alvarado 00043 * 00044 * \author Pablo Alvarado 00045 * \date 08.01.2008 00046 * 00047 * revisions ..: $Id: cvrLocationMatch.h,v 1.2 2008/01/16 21:52:27 alvarado Exp $ 00048 */ 00049 00050 #ifndef _CVR_LOCATION_MATCH_H_ 00051 #define _CVR_LOCATION_MATCH_H_ 00052 00053 #include "cvrLocation.h" 00054 #include "cvrVector.h" 00055 #include "cvrMatrix.h" 00056 #include "cvrList.h" 00057 00058 #include "cvrFunctor.h" 00059 00060 namespace cvr { 00061 00062 /** 00063 * Class locationMatch 00064 * 00065 * This class is used to match the locations on two images, based on the 00066 * descriptors associated to each location. 00067 * 00068 * This class receives as input the output to any feature extraction functor 00069 * (e.g. cvr::surfLocalDescriptor). 00070 * 00071 * @see locationMatch::parameters. 00072 * 00073 * @ingroup gLocalFeatures 00074 */ 00075 class locationMatch : public functor { 00076 public: 00077 /** 00078 * Types of algorithms to perform the match. 00079 */ 00080 enum eMatchType { 00081 KdTreeBased, /*< Use a kd-Tree data structures to accelerate the 00082 search */ 00083 LinearSearch /*< Perform a linear search */ 00084 }; 00085 00086 /** 00087 * The parameters for the class locationMatch 00088 */ 00089 class parameters : public functor::parameters { 00090 public: 00091 /** 00092 * Default constructor 00093 */ 00094 parameters(); 00095 00096 /** 00097 * Copy constructor 00098 * @param other the parameters object to be copied 00099 */ 00100 parameters(const parameters& other); 00101 00102 /** 00103 * Destructor 00104 */ 00105 ~parameters(); 00106 00107 /** 00108 * Copy the contents of a parameters object 00109 * @param other the parameters object to be copied 00110 * @return a reference to this parameters object 00111 */ 00112 parameters& copy(const parameters& other); 00113 00114 /** 00115 * Copy the contents of a parameters object 00116 * @param other the parameters object to be copied 00117 * @return a reference to this parameters object 00118 */ 00119 parameters& operator=(const parameters& other); 00120 00121 /** 00122 * Returns the complete name of the parameters class. 00123 */ 00124 virtual const std::string& name() const; 00125 00126 /** 00127 * Returns a pointer to a clone of the parameters. 00128 */ 00129 virtual parameters* clone() const; 00130 00131 /** 00132 * Returns a pointer to a new instance of the parameters. 00133 */ 00134 virtual parameters* newInstance() const; 00135 00136 /** 00137 * Write the parameters in the given ioHandler 00138 * @param handler the ioHandler to be used 00139 * @param complete if true (the default) the enclosing begin/end will 00140 * be also written, otherwise only the data block will be written. 00141 * @return true if write was successful 00142 */ 00143 virtual bool write(ioHandler& handler,const bool complete=true) const; 00144 00145 /** 00146 * Read the parameters from the given ioHandler 00147 * @param handler the ioHandler to be used 00148 * @param complete if true (the default) the enclosing begin/end will 00149 * be also written, otherwise only the data block will be written. 00150 * @return true if write was successful 00151 */ 00152 virtual bool read(ioHandler& handler,const bool complete=true); 00153 00154 // ------------------------------------------------ 00155 // the parameters 00156 // ------------------------------------------------ 00157 00158 /** 00159 * Bidirectional match. 00160 * 00161 * The match process can be unidirectional, in which the closest 00162 * descriptor in the second image is searched for each descriptor in the 00163 * first image (set this attribute to \c false). It can also be 00164 * bidirectional, which means that a match is found only if the 00165 * descriptor of the second image is the closest to the one of the first 00166 * image and the descriptor in the first image is the closest to the one 00167 * in the second image. 00168 * 00169 * Note that the bidirectional is slower, but more robust. 00170 * 00171 * Default value: true 00172 */ 00173 bool bidirectional; 00174 00175 /** 00176 * Threshold distance. 00177 * 00178 * The distance between two descriptors must be less than this threshold. 00179 * This means, the higher the given value, the greater the number of 00180 * matches detected. For lower values, just the most similar locations 00181 * are detected. 00182 * 00183 * Note that the threshold is an absolute value, whose range will depend 00184 * on the distances between points found by the other classes. 00185 * 00186 * Default value: 1.0 00187 */ 00188 double threshold; 00189 00190 /** 00191 * Algorithm used for the match. 00192 * 00193 * You can choose between several algorithms to perform the match. The 00194 * straightforward method is based on a linear search, while more 00195 * elaborate methods use a kd-tree. Use the second if the set of 00196 * locations is too large size. 00197 * 00198 * Default value: LinearSearch 00199 */ 00200 eMatchType matchType; 00201 00202 /** 00203 * Bucket size 00204 * 00205 * If the match method is set to KdTreeBased then the trees build will 00206 * use "buckets" of the given size, which means that at each leaf, the 00207 * given number of elements are stored, implying linear search for that 00208 * size. The experience tells that setting this value to 1 (a pure tree) 00209 * is not very efficient, since the time to create the tree will simply 00210 * be too high. The maximum efficiency is achieved usually with buckets 00211 * of 16 to 32 elements. 00212 * 00213 * Default value: 32 00214 */ 00215 int bucketSize; 00216 00217 }; 00218 00219 /** 00220 * Default constructor 00221 */ 00222 locationMatch(); 00223 00224 /** 00225 * Construct a functor using the given parameters 00226 */ 00227 locationMatch(const parameters& par); 00228 00229 /** 00230 * Copy constructor 00231 * @param other the object to be copied 00232 */ 00233 locationMatch(const locationMatch& other); 00234 00235 /** 00236 * Destructor 00237 */ 00238 virtual ~locationMatch(); 00239 00240 /** 00241 * Find the matches between the locations and descriptors of two different 00242 * images. 00243 * 00244 * This method finds the matching locations in two images A and B. 00245 * 00246 * @param locsA locations of the image A 00247 * @param vctsA descriptors for the locations of image A. 00248 * @param locsB locations of the image B 00249 * @param vctsB descriptors for the locations of image B. 00250 * @param matchedLocsA locations for which a match in image B has been 00251 * found. 00252 * @param descA descriptors corresponding to the matchedLocsA 00253 * @param matchedLocsB locations for which a match in image A has been 00254 * found. 00255 * @param descB descriptors corresponding to the matchedLocsB 00256 * 00257 * @return true if apply successful or false otherwise. 00258 */ 00259 bool apply(const list<location>& locsA, 00260 const std::list<dvector>& vctsA, 00261 const list<location>& locsB, 00262 const std::list<dvector>& vctsB, 00263 std::vector<location>& matchedLocsA, 00264 std::vector<dvector>& descA, 00265 std::vector<location>& matchedLocsB, 00266 std::vector<dvector>& descB); 00267 00268 00269 /** 00270 * Copy data of "other" functor. 00271 * @param other the functor to be copied 00272 * @return a reference to this functor object 00273 */ 00274 locationMatch& copy(const locationMatch& other); 00275 00276 /** 00277 * Alias for copy member 00278 * @param other the functor to be copied 00279 * @return a reference to this functor object 00280 */ 00281 locationMatch& operator=(const locationMatch& other); 00282 00283 /** 00284 * Returns the complete name of the functor class 00285 */ 00286 virtual const std::string& name() const; 00287 00288 /** 00289 * Returns a pointer to a clone of this functor. 00290 */ 00291 virtual locationMatch* clone() const; 00292 00293 /** 00294 * Returns a pointer to a new instance of this functor. 00295 */ 00296 virtual locationMatch* newInstance() const; 00297 00298 /** 00299 * Returns used parameters 00300 */ 00301 const parameters& getParameters() const; 00302 00303 /** 00304 * Linear search 00305 */ 00306 bool linearSearch(const list<location>& locsA, 00307 const std::list<dvector>& vctsA, 00308 const list<location>& locsB, 00309 const std::list<dvector>& vctsB, 00310 std::vector<location>& matchedLocsA, 00311 std::vector<dvector>& descA, 00312 std::vector<location>& matchedLocsB, 00313 std::vector<dvector>& descB); 00314 00315 /** 00316 * Search with kd-trees 00317 */ 00318 bool kdtree(const list<location>& locsA, 00319 const std::list<dvector>& vctsA, 00320 const list<location>& locsB, 00321 const std::list<dvector>& vctsB, 00322 std::vector<location>& matchedLocsA, 00323 std::vector<dvector>& descA, 00324 std::vector<location>& matchedLocsB, 00325 std::vector<dvector>& descB); 00326 00327 /** 00328 * Convert the two locations/vectors 00329 */ 00330 template<class T,class L> 00331 void convert(const L& theList, 00332 std::vector<T>& theVct) const; 00333 00334 }; 00335 00336 00337 /** 00338 * Read a surfLocalDescriptor::eOrientationMode value 00339 * 00340 * @ingroup gStorable 00341 */ 00342 bool read(ioHandler& handler, 00343 locationMatch::eMatchType& data); 00344 00345 /** 00346 * Write a surfLocalDescriptor::eOrientationMode value 00347 * 00348 * @ingroup gStorable 00349 */ 00350 bool write(ioHandler& handler, 00351 const locationMatch::eMatchType& data); 00352 00353 00354 00355 } 00356 00357 #endif 00358