ViSP  2.6.2
testFindMatch.cpp
1 /****************************************************************************
2  *
3  * $Id: testFindMatch.cpp 3820 2012-06-27 13:13:29Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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  * Compute the pose of a 3D object using the Dementhon method. Assuming that
36  * the correspondance between 2D points and 3D points is not done, we use
37  * the RANSAC algorithm to achieve this task
38  *
39  * Authors:
40  * Aurelien Yol
41  *
42  *****************************************************************************/
43 
44 #include <visp/vpPose.h>
45 #include <visp/vpPoint.h>
46 #include <visp/vpMath.h>
47 #include <visp/vpHomogeneousMatrix.h>
48 
49 #include <stdlib.h>
50 #include <stdio.h>
51 
52 #define L 0.1
53 
54 
62 int
63 main()
64 {
65  {
66  std::cout << "Find Matches using Ransac" << std::endl;
67  unsigned int nb3D = 4;
68  unsigned int nb2D = 8;
69  std::vector<vpPoint> P(nb3D);
70  std::vector<vpPoint> p(nb2D);
71 
72  P[0].setWorldCoordinates(-L,-L, 0 ) ;
73  P[1].setWorldCoordinates(L,-L, 0 ) ;
74  P[2].setWorldCoordinates(L,L, 0 ) ;
75  P[3].setWorldCoordinates(-L,L, 0 ) ;
76  //P[4].setWorldCoordinates(-0,0, L ) ; //ERREUR DANS LAGRANGE ET DEMENTHON
77 
78  vpHomogeneousMatrix cMo_ref(0,0.2,1,vpMath::rad(0),0,0) ;
79 
80  for(unsigned int i=0 ; i < nb3D ; i++)
81  {
82  vpPoint pt = P[i];
83  pt.project(cMo_ref);
84  p[i].set_x(pt.get_x());
85  p[i].set_y(pt.get_y());
86  }
87 
88  p[4].set_x(0.02) ;
89  p[4].set_y(0.05) ;
90 
91  p[5].set_x(0.02) ;
92  p[5].set_y(-0.05) ;
93 
94  p[6].set_x(0.07) ;
95  p[6].set_y(-0.05) ;
96 
97  p[7].set_x(0.24) ;
98  p[7].set_y(0.07) ;
99 
100  unsigned int ninliers ;
101  std::vector<vpPoint> inliers;
102  double threshold = 1e-6;
103  unsigned int nbInlierToReachConsensus = 4;
104 
105  vpHomogeneousMatrix cMo ;
106 
107  vpPose::findMatch(p,P,nbInlierToReachConsensus,threshold,ninliers,inliers,cMo);
108 
109  std::cout << "Inliers: " << std::endl;
110  for (unsigned int i = 0; i < inliers.size() ; i++)
111  {
112  inliers[i].print() ;
113  std::cout << std::endl;
114  }
115 
116  std::cout << "cMo :\n" << vpPoseVector(cMo).t() << std::endl << std::endl;
117 
118  }
119 }
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.h:145
static void findMatch(std::vector< vpPoint > &p2D, std::vector< vpPoint > &p3D, const int &numberOfInlierToReachAConsensus, const double &threshold, unsigned int &ninliers, std::vector< vpPoint > &listInliers, vpHomogeneousMatrix &cMo, const int &maxNbTrials=10000)
Class that defines what is a point.
Definition: vpPoint.h:65
vpRowVector t() const
transpose of Vector
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.h:143
static double rad(double deg)
Definition: vpMath.h:100
The pose is a complete representation of every rigid motion in the euclidian space.
Definition: vpPoseVector.h:92