Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpHomography.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Homography transformation.
32  *
33  * Authors:
34  * Muriel Pressigout
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 
47 #ifndef vpHomography_hh
48 #define vpHomography_hh
49 
50 #include <list>
51 #include <vector>
52 
53 #include <visp3/core/vpCameraParameters.h>
54 #include <visp3/core/vpImagePoint.h>
55 #include <visp3/core/vpHomogeneousMatrix.h>
56 #include <visp3/core/vpPlane.h>
57 #include <visp3/core/vpPoint.h>
58 #include <visp3/core/vpImagePoint.h>
59 #include <visp3/core/vpMatrix.h>
60 
179 class VISP_EXPORT vpHomography : public vpArray2D<double>
180 {
181  private:
182  static const double sing_threshold; // = 0.0001;
183  static const double threshold_rotation;
184  static const double threshold_displacement;
185  vpHomogeneousMatrix aMb ;
186  // bool isplanar;
188  vpPlane bP ;
189 
190  private:
192  void build() ;
193 
195  void insert(const vpHomogeneousMatrix &aRb) ;
197  void insert(const vpRotationMatrix &aRb) ;
199  void insert(const vpThetaUVector &tu) ;
201  void insert(const vpTranslationVector &atb) ;
203  void insert(const vpPlane &bP) ;
204 
205  static void initRansac(unsigned int n,
206  double *xb, double *yb,
207  double *xa, double *ya,
208  vpColVector &x) ;
209 
210  public:
211  vpHomography() ;
212  vpHomography(const vpHomography &H) ;
214  vpHomography(const vpHomogeneousMatrix &aMb, const vpPlane &bP) ;
216  vpHomography(const vpRotationMatrix &aRb,
217  const vpTranslationVector &atb,
218  const vpPlane &bP) ;
220  vpHomography(const vpThetaUVector &tu,
221  const vpTranslationVector &atb,
222  const vpPlane &bP) ;
224  vpHomography(const vpPoseVector &arb,
225  const vpPlane &bP) ;
226  virtual ~vpHomography() {};
227 
229  void buildFrom(const vpRotationMatrix &aRb,
230  const vpTranslationVector &atb,
231  const vpPlane &bP) ;
233  void buildFrom(const vpThetaUVector &tu,
234  const vpTranslationVector &atb,
235  const vpPlane &bP) ;
237  void buildFrom(const vpPoseVector &arb,
238  const vpPlane &bP) ;
240  void buildFrom(const vpHomogeneousMatrix &aMb,
241  const vpPlane &bP) ;
242  vpMatrix convert() const;
243 
244  void computeDisplacement(vpRotationMatrix &aRb,
245  vpTranslationVector &atb,
246  vpColVector &n) ;
247 
248  void computeDisplacement(const vpColVector& nd,
249  vpRotationMatrix &aRb,
250  vpTranslationVector &atb,
251  vpColVector &n) ;
252 
253  void eye();
254 
256  vpHomography inverse() const ;
258  void inverse(vpHomography &Hi) const;
259 
261  void load(std::ifstream &f) ;
262 
263  // Multiplication by an homography
264  vpHomography operator*(const vpHomography &H) const;
265  // Multiplication by a scalar
266  vpHomography operator*(const double &v) const;
267  vpColVector operator*(const vpColVector &b) const;
268  // Multiplication by a point
269  vpPoint operator*(const vpPoint &H) const;
270 
271  // Division by a scalar
272  vpHomography operator/(const double &v) const;
273  vpHomography & operator/=(double v);
274  vpHomography & operator=(const vpHomography &H);
275  vpHomography & operator=(const vpMatrix &H);
276 
277  vpImagePoint projection(const vpImagePoint &p);
278 
284  void resize(const unsigned int nrows, const unsigned int ncols,
285  const bool flagNullify = true)
286  {
287  (void)nrows;
288  (void)ncols;
289  (void)flagNullify;
290  throw(vpException(vpException::fatalError, "Cannot resize an homography matrix"));
291  };
292 
293  void save(std::ofstream &f) const ;
294 
295  static void DLT(const std::vector<double> &xb, const std::vector<double> &yb,
296  const std::vector<double> &xa, const std::vector<double> &ya ,
297  vpHomography &aHb,
298  bool normalization=true);
299 
300  static void HLM(const std::vector<double> &xb, const std::vector<double> &yb,
301  const std::vector<double> &xa, const std::vector<double> &ya,
302  bool isplanar,
303  vpHomography &aHb) ;
304 
305  static bool ransac(const std::vector<double> &xb, const std::vector<double> &yb,
306  const std::vector<double> &xa, const std::vector<double> &ya,
307  vpHomography &aHb,
308  std::vector<bool> &inliers,
309  double &residual,
310  unsigned int nbInliersConsensus,
311  double threshold,
312  bool normalization=true);
313 
314  static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa);
315  static vpPoint project(const vpHomography &bHa, const vpPoint &Pa);
316 
317  static void robust(const std::vector<double> &xb, const std::vector<double> &yb,
318  const std::vector<double> &xa, const std::vector<double> &ya,
319  vpHomography &aHb,
320  std::vector<bool> &inlier,
321  double &residual,
322  double weights_threshold=0.4,
323  unsigned int niter=4,
324  bool normalization=true);
325 
326 #ifndef DOXYGEN_SHOULD_SKIP_THIS
327  static void build(vpHomography &aHb,
329  const vpHomogeneousMatrix &aMb,
330  const vpPlane &bP) ;
331 
332  static void computeDisplacement(const vpHomography &aHb,
333  const vpColVector& nd,
334  vpRotationMatrix &aRb,
335  vpTranslationVector &atb,
336  vpColVector &n) ;
337 
338  static void computeDisplacement (const vpHomography &aHb,
339  vpRotationMatrix &aRb,
340  vpTranslationVector &atb,
341  vpColVector &n) ;
342 
343  static void computeDisplacement(const vpHomography &H,
344  const double x,
345  const double y,
346  std::list<vpRotationMatrix> & vR,
347  std::list<vpTranslationVector> & vT,
348  std::list<vpColVector> & vN) ;
349  static double computeDisplacement(unsigned int nbpoint,
350  vpPoint *c1P,
351  vpPoint *c2P,
352  vpPlane &oN,
353  vpHomogeneousMatrix &c2Mc1,
354  vpHomogeneousMatrix &c1Mo,
355  int userobust
356  ) ;
357  static double computeDisplacement(unsigned int nbpoint,
358  vpPoint *c1P,
359  vpPoint *c2P,
360  vpPlane *oN,
361  vpHomogeneousMatrix &c2Mc1,
362  vpHomogeneousMatrix &c1Mo,
363  int userobust
364  ) ;
365  static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d);
366  // VVS
367  static double computeRotation(unsigned int nbpoint,
368  vpPoint *c1P,
369  vpPoint *c2P,
370  vpHomogeneousMatrix &c2Mc1,
371  int userobust) ;
372  static void computeTransformation(vpColVector &x,unsigned int *ind, vpColVector &M) ;
373  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind) ;
374  static bool degenerateConfiguration(vpColVector &x,unsigned int *ind, double threshold_area);
375  static bool degenerateConfiguration(const std::vector<double> &xb, const std::vector<double> &yb,
376  const std::vector<double> &xa, const std::vector<double> &ya);
377  static void HartleyNormalization(unsigned int n,
378  const double *x, const double *y,
379  double *xn, double *yn,
380  double &xg, double &yg,
381  double &coef);
382  static void HartleyNormalization(const std::vector<double> &x, const std::vector<double> &y,
383  std::vector<double> &xn, std::vector<double> &yn,
384  double &xg, double &yg, double &coef);
385  static void HartleyDenormalization(vpHomography &aHbn,
386  vpHomography &aHb,
387  double xg1, double yg1, double coef1,
388  double xg2, double yg2, double coef2 ) ;
389 
390 #endif // DOXYGEN_SHOULD_SKIP_THIS
391 
392 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
393 
397  void setIdentity();
399 #endif
400 
401 };
402 
403 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
static bool save(const std::string &filename, const vpArray2D< Type > &A, const bool binary=false, const char *header="")
Definition: vpArray2D.h:499
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition: vpArray2D.h:239
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
Definition: vpException.h:73
Implementation of a generic 2D array used as vase class of matrices and vectors.
Definition: vpArray2D.h:70
Class that defines what is a point.
Definition: vpPoint.h:59
Implementation of a rotation matrix and operations on such kind of matrices.
vpColVector operator*(const double &x, const vpColVector &v)
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
virtual ~vpHomography()
Definition: vpHomography.h:226
static bool load(const std::string &filename, vpArray2D< Type > &A, const bool binary=false, char *header=NULL)
Definition: vpArray2D.h:308
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpHomography.h:284
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:58
Class that consider the case of a translation vector.
Implementation of a rotation vector as axis-angle minimal representation.