ViSP  2.6.2
vpHomography.h
1 /****************************************************************************
2  *
3  * $Id: vpHomography.h 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Homography transformation.
36  *
37  * Authors:
38  * Muriel Pressigout
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
51 #ifndef vpHomography_hh
52 #define vpHomography_hh
53 
54 #include <visp/vpHomogeneousMatrix.h>
55 #include <visp/vpPlane.h>
56 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
57 # include <visp/vpList.h>
58 #endif
59 
60 #include <list>
61 
174 class VISP_EXPORT vpHomography : public vpMatrix
175 {
176 
177 private:
178  static const double sing_threshold; // = 0.0001;
179  static const double threshold_rotation;
180  static const double threshold_displacement;
181  vpHomogeneousMatrix aMb ;
182  // bool isplanar;
184  vpPlane bP ;
185  void init() ;
186 
187 private:
189  void insert(const vpHomogeneousMatrix &aRb) ;
191  void insert(const vpRotationMatrix &aRb) ;
193  void insert(const vpThetaUVector &tu) ;
195  void insert(const vpTranslationVector &atb) ;
197  void insert(const vpPlane &bP) ;
198 
199  static void HartleyNormalization(unsigned int n,
200  double *x, double *y,
201  double *xn, double *yn,
202  double &xg, double &yg,
203  double &coef);
204  static void HartleyDenormalization(vpHomography &aHbn,
205  vpHomography &aHb,
206  double xg1, double yg1, double coef1,
207  double xg2, double yg2, double coef2 ) ;
208 
209  static void initRansac(unsigned int n,
210  double *xb, double *yb,
211  double *xa, double *ya,
212  vpColVector &x
213  ) ;
214 
215 public:
216  vpHomography() ;
217 
219  vpHomography(const vpHomography &aMb) ;
222  const vpPlane &bP) ;
224  vpHomography(const vpRotationMatrix &aRb,
225  const vpTranslationVector &atb,
226  const vpPlane &bP) ;
228  vpHomography(const vpThetaUVector &tu,
229  const vpTranslationVector &atb,
230  const vpPlane &bP) ;
232  vpHomography(const vpPoseVector &arb,
233  const vpPlane &bP) ;
234  virtual ~vpHomography() { }
235 
237  void buildFrom(const vpRotationMatrix &aRb,
238  const vpTranslationVector &atb,
239  const vpPlane &bP) ;
241  void buildFrom(const vpThetaUVector &tu,
242  const vpTranslationVector &atb,
243  const vpPlane &bP) ;
245  void buildFrom(const vpPoseVector &arb,
246  const vpPlane &bP) ;
248  void buildFrom(const vpHomogeneousMatrix &aMb,
249  const vpPlane &bP) ;
250 
252  void build() ;
253 
254 
255  void computeDisplacement(vpRotationMatrix &aRb,
256  vpTranslationVector &atb,
257  vpColVector &n) ;
258 
259  void computeDisplacement(const vpColVector& nd,
260  vpRotationMatrix &aRb,
261  vpTranslationVector &atb,
262  vpColVector &n) ;
263 
265  void load(std::ifstream &f) ;
267  void print() ;
269  void save(std::ofstream &f) const ;
270 
272  vpHomography inverse() const ;
274  void inverse(vpHomography &Hi) const;
275 
276  // Multiplication by an homography
277  vpHomography operator*(const vpHomography &H) const;
278 
279  // Multiplication by a scalar
280  vpHomography operator*(const double &v) const;
281 
282  // Division by a scalar
283  vpHomography operator/(const double &v) const;
284 
286  static void build(vpHomography &aHb,
287  const vpHomogeneousMatrix &aMb,
288  const vpPlane &bP) ;
289 
290  static void DLT(unsigned int n,
291  double *xb, double *yb ,
292  double *xa, double *ya,
293  vpHomography &aHb) ;
294 
295  static void HartleyDLT(unsigned int n,
296  double *xb, double *yb ,
297  double *xa, double *ya,
298  vpHomography &aHb) ;
299  static void HLM(unsigned int n,
300  double *xb, double *yb,
301  double *xa, double *ya ,
302  bool isplan,
303  vpHomography &aHb) ;
304 
305  static void computeDisplacement(const vpHomography &aHb,
306  const vpColVector& nd,
307  vpRotationMatrix &aRb,
308  vpTranslationVector &atb,
309  vpColVector &n) ;
310 
311  static void computeDisplacement (const vpHomography &aHb,
312  vpRotationMatrix &aRb,
313  vpTranslationVector &atb,
314  vpColVector &n) ;
315 
316  static void computeDisplacement(const vpMatrix &H,
317  const double x,
318  const double y,
319  std::list<vpRotationMatrix> & vR,
320  std::list<vpTranslationVector> & vT,
321  std::list<vpColVector> & vN) ;
322  static double computeDisplacement(unsigned int nbpoint,
323  vpPoint *c1P,
324  vpPoint *c2P,
325  vpPlane &oN,
326  vpHomogeneousMatrix &c2Mc1,
327  vpHomogeneousMatrix &c1Mo,
328  int userobust
329  ) ;
330  static double computeDisplacement(unsigned int nbpoint,
331  vpPoint *c1P,
332  vpPoint *c2P,
333  vpPlane *oN,
334  vpHomogeneousMatrix &c2Mc1,
335  vpHomogeneousMatrix &c1Mo,
336  int userobust
337  ) ;
338  static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d);
339  // VVS
340  static double computeRotation(unsigned int nbpoint,
341  vpPoint *c1P,
342  vpPoint *c2P,
343  vpHomogeneousMatrix &c2Mc1,
344  int userobust
345  ) ;
346  static void computeTransformation(vpColVector &x,unsigned int *ind, vpColVector &M) ;
347 
348  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind) ;
349  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind, double threshold_area);
350 
351  static bool ransac(unsigned int n,
352  double *xb, double *yb,
353  double *xa, double *ya ,
354  vpHomography &aHb,
355  int consensus = 1000,
356  double threshold = 1e-6
357  ) ;
358 
359  static bool ransac(unsigned int n,
360  double *xb, double *yb,
361  double *xa, double *ya ,
362  vpHomography &aHb,
363  vpColVector& inliers,
364  double& residual,
365  int consensus = 1000,
366  double epsilon = 1e-6,
367  double areaThreshold = 0.0);
368 
369 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
370 
373  vp_deprecated static void computeDisplacement(const vpMatrix H,
374  const double x,
375  const double y,
378  vpList<vpColVector> & vN) ;
379 
380 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
381 } ;
382 
383 
384 
385 #endif
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
void init()
Initialization of the object matrix.
Definition: vpMatrix.cpp:93
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Provide simple list management.
Definition: vpList.h:112
int print(std::ostream &s, unsigned int length, char const *intro=0)
Definition: vpMatrix.cpp:2613
Class that defines what is a point.
Definition: vpPoint.h:65
The vpRotationMatrix considers the particular case of a rotation matrix.
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:174
void insert(const vpMatrix &A, const unsigned int r, const unsigned int c)
Definition: vpMatrix.cpp:2908
virtual ~vpHomography()
Definition: vpHomography.h:234
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
The pose is a complete representation of every rigid motion in the euclidian space.
Definition: vpPoseVector.h:92
vpMatrix operator/(const double x) const
Cij = Aij / x (A is unchanged)
Definition: vpMatrix.cpp:963
vpMatrix operator*(const vpMatrix &B) const
Definition: vpMatrix.cpp:434
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:67
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.