Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpHomography.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
41#ifndef vpHomography_hh
42#define vpHomography_hh
43
44#include <list>
45#include <vector>
46
47#include <visp3/core/vpCameraParameters.h>
48#include <visp3/core/vpHomogeneousMatrix.h>
49#include <visp3/core/vpImagePoint.h>
50#include <visp3/core/vpMatrix.h>
51#include <visp3/core/vpPlane.h>
52#include <visp3/core/vpPoint.h>
53
167class VISP_EXPORT vpHomography : public vpArray2D<double>
168{
169private:
170 static const double sing_threshold; // = 0.0001;
171 static const double threshold_rotation;
172 static const double threshold_displacement;
174 // bool isplanar;
176 vpPlane bP;
177
178private:
180 void build();
181
186 void insert(const vpHomogeneousMatrix &aRb);
187
192 void insert(const vpRotationMatrix &aRb);
193
198 void insert(const vpThetaUVector &tu);
199
204 void insert(const vpTranslationVector &atb);
205
210 void insert(const vpPlane &bP);
211
212 static void initRansac(unsigned int n, double *xb, double *yb, double *xa, double *ya, vpColVector &x);
213
214public:
218 vpHomography();
222 vpHomography(const vpHomography &H);
224 vpHomography(const vpHomogeneousMatrix &aMb, const vpPlane &bP);
226 vpHomography(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP);
228 vpHomography(const vpThetaUVector &tu, const vpTranslationVector &atb, const vpPlane &bP);
230 vpHomography(const vpPoseVector &arb, const vpPlane &bP);
232 virtual ~vpHomography() { };
233
235 void buildFrom(const vpRotationMatrix &aRb, const vpTranslationVector &atb, const vpPlane &bP);
237 void buildFrom(const vpThetaUVector &tu, const vpTranslationVector &atb, const vpPlane &bP);
239 void buildFrom(const vpPoseVector &arb, const vpPlane &bP);
241 void buildFrom(const vpHomogeneousMatrix &aMb, const vpPlane &bP);
242
261 vpHomography collineation2homography(const vpCameraParameters &cam) const;
262
267 vpMatrix convert() const;
268
277 void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n);
278
294 void computeDisplacement(const vpColVector &nd, vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n);
295
299 double det() const;
300
305 void eye();
306
325 vpHomography homography2collineation(const vpCameraParameters &cam) const;
326
338 vpHomography inverse(double sv_threshold = 1e-16, unsigned int *rank = NULL) const;
339
345 void inverse(vpHomography &bHa) const;
346
355 void load(std::ifstream &f);
356
368 vpHomography operator*(const vpHomography &H) const;
369
382 vpHomography operator*(const double &v) const;
383
389 vpColVector operator*(const vpColVector &b) const;
390
400 vpPoint operator*(const vpPoint &b_P) const;
401
413 vpHomography operator/(const double &v) const;
414
418 vpHomography &operator/=(double v);
419
427
435
443 vpImagePoint projection(const vpImagePoint &ipb);
444
450 void resize(unsigned int nrows, unsigned int ncols, bool flagNullify = true)
451 {
452 (void)nrows;
453 (void)ncols;
454 (void)flagNullify;
455 throw(vpException(vpException::fatalError, "Cannot resize an homography matrix"));
456 };
457
465 void save(std::ofstream &f) const;
466
534 static void DLT(const std::vector<double> &xb, const std::vector<double> &yb, const std::vector<double> &xa,
535 const std::vector<double> &ya, vpHomography &aHb, bool normalization = true);
536
561 static void HLM(const std::vector<double> &xb, const std::vector<double> &yb, const std::vector<double> &xa,
562 const std::vector<double> &ya, bool isplanar, vpHomography &aHb);
563
591 static bool ransac(const std::vector<double> &xb, const std::vector<double> &yb, const std::vector<double> &xa,
592 const std::vector<double> &ya, vpHomography &aHb, std::vector<bool> &inliers, double &residual,
593 unsigned int nbInliersConsensus, double threshold, bool normalization = true);
594
607 static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa);
608
621 static vpPoint project(const vpHomography &bHa, const vpPoint &Pa);
622
656 static void robust(const std::vector<double> &xb, const std::vector<double> &yb, const std::vector<double> &xa,
657 const std::vector<double> &ya, vpHomography &aHb, std::vector<bool> &inliers, double &residual,
658 double weights_threshold = 0.4, unsigned int niter = 4, bool normalization = true);
659
660#ifndef DOXYGEN_SHOULD_SKIP_THIS
662 static void build(vpHomography &aHb, const vpHomogeneousMatrix &aMb, const vpPlane &bP);
663
664 static void computeDisplacement(const vpHomography &aHb, const vpColVector &nd, vpRotationMatrix &aRb,
666
667 static void computeDisplacement(const vpHomography &aHb, vpRotationMatrix &aRb, vpTranslationVector &atb,
668 vpColVector &n);
669
670 static void computeDisplacement(const vpHomography &H, double x, double y, std::list<vpRotationMatrix> &vR,
671 std::list<vpTranslationVector> &vT, std::list<vpColVector> &vN);
672 static double computeDisplacement(unsigned int nbpoint, vpPoint *c1P, vpPoint *c2P, vpPlane &oN,
673 vpHomogeneousMatrix &c2Mc1, vpHomogeneousMatrix &c1Mo, int userobust);
674 static double computeDisplacement(unsigned int nbpoint, vpPoint *c1P, vpPoint *c2P, vpPlane *oN,
675 vpHomogeneousMatrix &c2Mc1, vpHomogeneousMatrix &c1Mo, int userobust);
676 static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d);
677 // VVS
678 static double computeRotation(unsigned int nbpoint, vpPoint *c1P, vpPoint *c2P, vpHomogeneousMatrix &c2Mc1,
679 int userobust);
680 static void computeTransformation(vpColVector &x, unsigned int *ind, vpColVector &M);
681 static bool degenerateConfiguration(const vpColVector &x, unsigned int *ind);
682 static bool degenerateConfiguration(const vpColVector &x, unsigned int *ind, double threshold_area);
683 static bool degenerateConfiguration(const std::vector<double> &xb, const std::vector<double> &yb,
684 const std::vector<double> &xa, const std::vector<double> &ya);
685 static void HartleyNormalization(unsigned int n, const double *x, const double *y, double *xn, double *yn, double &xg,
686 double &yg, double &coef);
687 static void HartleyNormalization(const std::vector<double> &x, const std::vector<double> &y, std::vector<double> &xn,
688 std::vector<double> &yn, double &xg, double &yg, double &coef);
689 static void HartleyDenormalization(vpHomography &aHbn, vpHomography &aHb, double xg1, double yg1, double coef1,
690 double xg2, double yg2, double coef2);
691
692#endif // DOXYGEN_SHOULD_SKIP_THIS
693
694#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
699 void setIdentity();
701#endif
702};
703
704#endif
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:131
static bool load(const std::string &filename, vpArray2D< Type > &A, bool binary=false, char *header=NULL)
Definition vpArray2D.h:582
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition vpArray2D.h:445
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition vpArray2D.h:417
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:59
@ fatalError
Fatal error.
Definition vpException.h:84
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of an homography and operations on homographies.
virtual ~vpHomography()
Destructor.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
This class defines the container for a plane geometrical structure.
Definition vpPlane.h:54
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:77
Implementation of a pose vector and operations on poses.
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.
vpColVector operator*(const double &x, const vpColVector &v)