ViSP  2.10.0
tutorial-homography-from-points.cpp
1 
4 #include <visp/vpHomography.h>
6 #include <visp/vpMeterPixelConversion.h>
7 
8 int main()
9 {
11  double L = 0.1;
12  std::vector<vpPoint> oP(4);
13  oP[0].setWorldCoordinates( -L,-L, 0);
14  oP[1].setWorldCoordinates(2*L,-L, 0);
15  oP[2].setWorldCoordinates( L, 3*L, 0);
16  oP[3].setWorldCoordinates( -L, 4*L, 0);
18 
20  vpHomogeneousMatrix bMo(0.1, 0, 1, 0, vpMath::rad(15), 0);
21  vpHomogeneousMatrix aMb(0.2, -0.1, 0.1, vpMath::rad(-3), vpMath::rad(20), vpMath::rad(5));
22  vpHomogeneousMatrix aMo = aMb*bMo;
24 
26  std::vector<vpPoint> aP(4), bP(4);
27  std::vector<double> xa(4), ya(4), xb(4), yb(4);
28  for(unsigned int i=0 ; i < 4; i++)
29  {
30  oP[i].project(aMo);
31  xa[i] = oP[i].get_x();
32  ya[i] = oP[i].get_y();
33  oP[i].project(bMo);
34  xb[i] = oP[i].get_x();
35  yb[i] = oP[i].get_y();
36  }
38 
40  vpHomography aHb ;
41  vpHomography::DLT(xb, yb, xa, ya, aHb, true);
42  std::cout << "Estimated homography using DLT:\n" << aHb/aHb[2][2] << std::endl;
43 
44  vpHomography::HLM(xb, yb, xa, ya, true, aHb);
45  std::cout << "Estimated homography using HLM:\n" << aHb/aHb[2][2] << std::endl;
47 
49  vpRotationMatrix aRb;
51  vpColVector n;
52  aHb.computeDisplacement(aRb, atb, n);
54 
56  std::cout << "\nEstimated displacement:" << std::endl;
57  std::cout << " atb: " << atb.t() << std::endl;
58  vpThetaUVector atub;
59  atub.buildFrom(aRb);
60  std::cout << " athetaub: ";
61  for(unsigned int i=0; i<3; i++)
62  std::cout << vpMath::deg(atub[i]) << " ";
63  std::cout << std::endl;
64  std::cout << " n: " << n.t() << std::endl;
66 
68  vpImagePoint iPa, iPb;
70  vpMeterPixelConversion::convertPoint(cam, xb[3], yb[3], iPb);
71  vpMeterPixelConversion::convertPoint(cam, xa[3], ya[3], iPa);
72 
73  std::cout << "Ground truth: Point 3 in pixels in frame b: " << iPb << std::endl;
74  std::cout << "Ground truth: Point 3 in pixels in frame a: " << iPa << std::endl;
76 
78  // Project the position in pixel of point 3 from the homography
79  std::cout << "Estimation from homography: Point 3 in pixels in frame a: "
80  << vpHomography::project(cam, aHb, iPb) << std::endl;
82 }
static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
void computeDisplacement(vpRotationMatrix &aRb, vpTranslationVector &atb, vpColVector &n)
static void HLM(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, bool isplanar, vpHomography &aHb)
The vpRotationMatrix considers the particular case of a rotation matrix.
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
vpRowVector t() const
Transpose of a vector.
Generic class defining intrinsic camera parameters.
static double rad(double deg)
Definition: vpMath.h:100
static void DLT(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, bool normalization=true)
static double deg(double rad)
Definition: vpMath.h:93
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.