ViSP  2.9.0
tutorial-homography-from-points.cpp
1 
2 #include <visp/vpHomography.h>
3 #include <visp/vpMeterPixelConversion.h>
4 
5 int main()
6 {
7  double L = 0.1;
8  std::vector<vpPoint> oP(4);
9  oP[0].setWorldCoordinates( -L,-L, 0);
10  oP[1].setWorldCoordinates(2*L,-L, 0);
11  oP[2].setWorldCoordinates( L, 3*L, 0);
12  oP[3].setWorldCoordinates( -L, 4*L, 0);
13 
14  vpHomogeneousMatrix bMo(0.1, 0, 1, 0, vpMath::rad(15), 0);
15  vpHomogeneousMatrix aMb(0.2, -0.1, 0.1, vpMath::rad(-3), vpMath::rad(20), vpMath::rad(5));
16  vpHomogeneousMatrix aMo = aMb*bMo;
17 
18  std::vector<vpPoint> aP(4), bP(4);
19  std::vector<double> xa(4), ya(4), xb(4), yb(4);
20  for(unsigned int i=0 ; i < 4; i++)
21  {
22  oP[i].project(aMo);
23  xa[i] = oP[i].get_x();
24  ya[i] = oP[i].get_y();
25  oP[i].project(bMo);
26  xb[i] = oP[i].get_x();
27  yb[i] = oP[i].get_y();
28  }
29 
30  vpHomography aHb ;
31  vpHomography::DLT(xb, yb, xa, ya, aHb, true);
32  std::cout << "Estimated homography using DLT:\n" << aHb/aHb[2][2] << std::endl;
33 
34  vpHomography::HLM(xb, yb, xa, ya, true, aHb);
35  std::cout << "Estimated homography using HLM:\n" << aHb/aHb[2][2] << std::endl;
36 
37  vpRotationMatrix aRb;
39  vpColVector n;
40  aHb.computeDisplacement(aRb, atb, n);
41 
42  std::cout << "\nEstimated displacement:" << std::endl;
43  std::cout << " atb: " << atb.t() << std::endl;
44  vpThetaUVector atub;
45  atub.buildFrom(aRb);
46  std::cout << " athetaub: ";
47  for(unsigned int i=0; i<3; i++)
48  std::cout << vpMath::deg(atub[i]) << " ";
49  std::cout << std::endl;
50  std::cout << " n: " << n.t() << std::endl;
51 
52  vpImagePoint iPa, iPb;
54  vpMeterPixelConversion::convertPoint(cam, xb[3], yb[3], iPb);
55  vpMeterPixelConversion::convertPoint(cam, xa[3], ya[3], iPa);
56 
57  std::cout << "Ground truth: Point 3 in pixels in frame b: " << iPb << std::endl;
58  std::cout << "Ground truth: Point 3 in pixels in frame a: " << iPa << std::endl;
59 
60  // Project the position in pixel of point 3 from the homography
61  std::cout << "Estimation from homography: Point 3 in pixels in frame a: "
62  << vpHomography::project(cam, aHb, iPb) << std::endl;
63 }
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 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:92
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.