ViSP  2.10.0
vpHomography.h
1 /****************************************************************************
2  *
3  * $Id: vpHomography.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 <list>
55 #include <vector>
56 
57 #include <visp/vpCameraParameters.h>
58 #include <visp/vpImagePoint.h>
59 #include <visp/vpHomogeneousMatrix.h>
60 #include <visp/vpPlane.h>
61 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
62 # include <visp/vpList.h>
63 #endif
64 
178 class VISP_EXPORT vpHomography
179 {
180  public:
182  double *data;
183 
184  private:
185  static const double sing_threshold; // = 0.0001;
186  static const double threshold_rotation;
187  static const double threshold_displacement;
188  vpHomogeneousMatrix aMb ;
189  // bool isplanar;
191  vpPlane bP ;
192 
193  private:
195  void build() ;
196 
198  void insert(const vpHomogeneousMatrix &aRb) ;
200  void insert(const vpRotationMatrix &aRb) ;
202  void insert(const vpThetaUVector &tu) ;
204  void insert(const vpTranslationVector &atb) ;
206  void insert(const vpPlane &bP) ;
207 
208  static void initRansac(unsigned int n,
209  double *xb, double *yb,
210  double *xa, double *ya,
211  vpColVector &x) ;
212 
213  public:
214  vpHomography() ;
215  vpHomography(const vpHomography &H) ;
218  const vpPlane &bP) ;
220  vpHomography(const vpRotationMatrix &aRb,
221  const vpTranslationVector &atb,
222  const vpPlane &bP) ;
224  vpHomography(const vpThetaUVector &tu,
225  const vpTranslationVector &atb,
226  const vpPlane &bP) ;
228  vpHomography(const vpPoseVector &arb,
229  const vpPlane &bP) ;
230  virtual ~vpHomography();
231 
233  void buildFrom(const vpRotationMatrix &aRb,
234  const vpTranslationVector &atb,
235  const vpPlane &bP) ;
237  void buildFrom(const vpThetaUVector &tu,
238  const vpTranslationVector &atb,
239  const vpPlane &bP) ;
241  void buildFrom(const vpPoseVector &arb,
242  const vpPlane &bP) ;
244  void buildFrom(const vpHomogeneousMatrix &aMb,
245  const vpPlane &bP) ;
246 
247  void computeDisplacement(vpRotationMatrix &aRb,
248  vpTranslationVector &atb,
249  vpColVector &n) ;
250 
251  void computeDisplacement(const vpColVector& nd,
252  vpRotationMatrix &aRb,
253  vpTranslationVector &atb,
254  vpColVector &n) ;
255 
257  inline unsigned int getRows() const { return 3;}
259  inline unsigned int getCols() const { return 3; }
260 
262  vpHomography inverse() const ;
264  void inverse(vpHomography &Hi) const;
265 
267  void load(std::ifstream &f) ;
268 
270  inline double *operator[](unsigned int i) { return &data[i*3]; }
272  inline double *operator[](unsigned int i) const {return &data[i*3];}
273 
274  // Multiplication by an homography
275  vpHomography operator*(const vpHomography &H) const;
276 
277  // Multiplication by a scalar
278  vpHomography operator*(const double &v) const;
279  vpColVector operator*(const vpColVector &b) const;
280 
281  // Division by a scalar
282  vpHomography operator/(const double &v) const;
283  vpHomography & operator/=(double v);
284  vpHomography & operator=(const vpHomography &H);
285  vpHomography & operator=(const vpMatrix &H);
286 
288  void save(std::ofstream &f) const ;
289 
290  void setIdentity();
291 
292  friend VISP_EXPORT std::ostream &operator << (std::ostream &s,const vpHomography &H);
293 
294  static void DLT(const std::vector<double> &xb, const std::vector<double> &yb,
295  const std::vector<double> &xa, const std::vector<double> &ya ,
296  vpHomography &aHb,
297  bool normalization=true);
298 
299  static void HLM(const std::vector<double> &xb, const std::vector<double> &yb,
300  const std::vector<double> &xa, const std::vector<double> &ya,
301  bool isplanar,
302  vpHomography &aHb) ;
303 
304  static bool ransac(const std::vector<double> &xb, const std::vector<double> &yb,
305  const std::vector<double> &xa, const std::vector<double> &ya,
306  vpHomography &aHb,
307  std::vector<bool> &inliers,
308  double &residual,
309  unsigned int nbInliersConsensus,
310  double threshold,
311  bool normalization=true);
312 
313  static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa);
314  static vpPoint project(const vpHomography &bHa, const vpPoint &Pa);
315 
316  static void robust(const std::vector<double> &xb, const std::vector<double> &yb,
317  const std::vector<double> &xa, const std::vector<double> &ya,
318  vpHomography &aHb,
319  std::vector<bool> &inlier,
320  double &residual,
321  double weights_threshold=0.4,
322  unsigned int niter=4,
323  bool normalization=true);
324 
325 #ifndef DOXYGEN_SHOULD_SKIP_THIS
326  static void build(vpHomography &aHb,
328  const vpHomogeneousMatrix &aMb,
329  const vpPlane &bP) ;
330 
331  static void computeDisplacement(const vpHomography &aHb,
332  const vpColVector& nd,
333  vpRotationMatrix &aRb,
334  vpTranslationVector &atb,
335  vpColVector &n) ;
336 
337  static void computeDisplacement (const vpHomography &aHb,
338  vpRotationMatrix &aRb,
339  vpTranslationVector &atb,
340  vpColVector &n) ;
341 
342  static void computeDisplacement(const vpMatrix &H,
343  const double x,
344  const double y,
345  std::list<vpRotationMatrix> & vR,
346  std::list<vpTranslationVector> & vT,
347  std::list<vpColVector> & vN) ;
348  static double computeDisplacement(unsigned int nbpoint,
349  vpPoint *c1P,
350  vpPoint *c2P,
351  vpPlane &oN,
352  vpHomogeneousMatrix &c2Mc1,
353  vpHomogeneousMatrix &c1Mo,
354  int userobust
355  ) ;
356  static double computeDisplacement(unsigned int nbpoint,
357  vpPoint *c1P,
358  vpPoint *c2P,
359  vpPlane *oN,
360  vpHomogeneousMatrix &c2Mc1,
361  vpHomogeneousMatrix &c1Mo,
362  int userobust
363  ) ;
364  static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d);
365  // VVS
366  static double computeRotation(unsigned int nbpoint,
367  vpPoint *c1P,
368  vpPoint *c2P,
369  vpHomogeneousMatrix &c2Mc1,
370  int userobust) ;
371  static void computeTransformation(vpColVector &x,unsigned int *ind, vpColVector &M) ;
372  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind) ;
373  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind, double threshold_area);
374  static bool degenerateConfiguration(const std::vector<double> &xb, const std::vector<double> &yb,
375  const std::vector<double> &xa, const std::vector<double> &ya);
376  static void HartleyNormalization(unsigned int n,
377  const double *x, const double *y,
378  double *xn, double *yn,
379  double &xg, double &yg,
380  double &coef);
381  static void HartleyNormalization(const std::vector<double> &x, const std::vector<double> &y,
382  std::vector<double> &xn, std::vector<double> &yn,
383  double &xg, double &yg, double &coef);
384  static void HartleyDenormalization(vpHomography &aHbn,
385  vpHomography &aHb,
386  double xg1, double yg1, double coef1,
387  double xg2, double yg2, double coef2 ) ;
388 
389 #endif // DOXYGEN_SHOULD_SKIP_THIS
390 
391 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
392 
395  vp_deprecated static void computeDisplacement(const vpMatrix H,
396  const double x,
397  const double y,
400  vpList<vpColVector> & vN);
401 
402  static void DLT(unsigned int n,
403  double *xb, double *yb ,
404  double *xa, double *ya,
405  vpHomography &aHb) ;
406  vp_deprecated static void HartleyDLT(unsigned int n,
407  double *xb, double *yb ,
408  double *xa, double *ya,
409  vpHomography &aHb) ;
410 
411  static void HLM(unsigned int n,
412  double *xb, double *yb,
413  double *xa, double *ya ,
414  bool isplan,
415  vpHomography &aHb) ;
416 
418  vp_deprecated void print() ;
419 
420  vp_deprecated static bool ransac(unsigned int n,
421  double *xb, double *yb,
422  double *xa, double *ya ,
423  vpHomography &aHb,
424  int consensus = 1000,
425  double threshold = 1e-6) ;
426 
427  vp_deprecated static bool ransac(unsigned int n,
428  double *xb, double *yb,
429  double *xa, double *ya ,
430  vpHomography &aHb,
431  vpColVector& inliers,
432  double residual = 0.1, // Not used
433  int consensus = 1000,
434  double threshold = 1e-6,
435  double areaThreshold = 0.0);
436 
437 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
438 } ;
439 
440 
441 
442 #endif
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
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:113
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:178
unsigned int getRows() const
Return the number of rows of the homography matrix.
Definition: vpHomography.h:257
Generic class defining intrinsic camera parameters.
unsigned int getCols() const
Return the number of columns of the homography matrix.
Definition: vpHomography.h:259
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
double * operator[](unsigned int i)
Write elements Hij (usage : H[i][j] = x )
Definition: vpHomography.h:270
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:67
double * data
Data array.
Definition: vpHomography.h:182
Class that consider the case of a translation vector.
double * operator[](unsigned int i) const
Read elements Hij (usage : x = H[i][j] )
Definition: vpHomography.h:272
Class that consider the case of the parameterization for the rotation.