44 #include <visp/vpPose.h>
45 #include <visp/vpPoint.h>
46 #include <visp/vpMath.h>
47 #include <visp/vpTranslationVector.h>
48 #include <visp/vpRxyzVector.h>
49 #include <visp/vpRotationMatrix.h>
50 #include <visp/vpHomogeneousMatrix.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpParseArgv.h>
58 #define GETOPTARGS "h"
70 void usage(
const char *name,
const char *badparam);
71 bool getOptions(
int argc,
const char **argv);
74 const std::string &legend);
82 void usage(
const char *name,
const char *badparam)
85 Compute the pose of a 3D object using the Dementhon, Lagrange and\n\
86 Non-Linear approach.\n\
97 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
106 bool getOptions(
int argc,
const char **argv)
113 case 'h': usage(argv[0], NULL);
return false;
break;
116 usage(argv[0], optarg_);
121 if ((c == 1) || (c == -1)) {
123 usage(argv[0], NULL);
124 std::cerr <<
"ERROR: " << std::endl;
125 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
137 std::cout << std::endl << legend <<
"\n "
138 <<
"tx = " << cpo[0] <<
"\n "
139 <<
"ty = " << cpo[1] <<
"\n "
140 <<
"tz = " << cpo[2] <<
"\n "
141 <<
"tux = vpMath::rad(" <<
vpMath::deg(cpo[3]) <<
")\n "
142 <<
"tuy = vpMath::rad(" <<
vpMath::deg(cpo[4]) <<
")\n "
143 <<
"tuz = vpMath::rad(" <<
vpMath::deg(cpo[5]) <<
")\n"
149 const std::string &legend)
157 for(
unsigned int i=0; i<6; i++) {
158 if (std::fabs(pose_ref[i]-pose_est[i]) > 0.001)
162 std::cout <<
"Based on 3D parameters " << legend <<
" is " << (fail ?
"badly" :
"well") <<
" estimated" << std::endl;
166 if (pose.
listP.size() < 4) {
168 std::cout <<
"Not enough point" << std::endl;
171 r = sqrt(r)/pose.
listP.size();
173 fail = (r > 0.1) ? 1 : 0;
174 std::cout <<
"Based on 2D residual (" << r <<
") " << legend <<
" is " << (fail ?
"badly" :
"well") <<
" estimated" << std::endl;
179 main(
int argc,
const char ** argv)
183 if (getOptions(argc, argv) ==
false) {
198 int test_fail = 0, fail = 0;
203 for(
int i=0 ; i < 5 ; i++) {
210 print_pose(cMo_ref, std::string(
"Reference pose"));
212 std::cout <<
"-------------------------------------------------"<<std::endl ;
215 print_pose(cMo, std::string(
"Pose estimated by Lagrange"));
216 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange");
219 std::cout <<
"--------------------------------------------------"<<std::endl ;
222 print_pose(cMo, std::string(
"Pose estimated by Dementhon"));
223 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon");
226 std::cout <<
"--------------------------------------------------"<<std::endl ;
231 print_pose(cMo, std::string(
"Pose estimated by Ransac"));
232 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Ransac");
235 std::cout <<
"--------------------------------------------------"<<std::endl ;
238 print_pose(cMo, std::string(
"Pose estimated by Lagrange than Lowe"));
239 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange than Lowe");
242 std::cout <<
"--------------------------------------------------"<<std::endl ;
245 print_pose(cMo, std::string(
"Pose estimated by Dementhon than Lowe"));
246 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon than Lowe");
251 std::cout <<
"--------------------------------------------------"<<std::endl ;
254 print_pose(cMo, std::string(
"Pose estimated by VVS"));
255 fail = compare_pose(pose, cMo_ref, cMo,
"pose by VVS");
258 std::cout <<
"-------------------------------------------------"<<std::endl ;
261 print_pose(cMo, std::string(
"Pose estimated by Dementhon than by VVS"));
262 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Dementhon than by VVS");
265 std::cout <<
"-------------------------------------------------"<<std::endl ;
268 print_pose(cMo, std::string(
"Pose estimated by Lagrange than by VVS"));
269 fail = compare_pose(pose, cMo_ref, cMo,
"pose by Lagrange than by VVS");
272 std::cout <<
"\nGlobal pose estimation test " << (test_fail ?
"fail" :
"is ok") << std::endl;
277 std::cout <<
"Catch an exception: " << e << std::endl;
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
void setRansacThreshold(const double &t)
std::list< vpPoint > listP
array of point (use here class vpPoint)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose for a given method
Class used for pose computation from N points (pose from point only).
static double rad(double deg)
void setRansacNbInliersToReachConsensus(const unsigned int &nbC)
static double deg(double rad)
The pose is a complete representation of every rigid motion in the euclidian space.
void addPoint(const vpPoint &P)
Add a new point in this array.
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the residual expressed in meter for the pose matrix 'cMo'.
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void clearPoint()
suppress all the point in the array of point