37 #include <visp3/vision/vpPoseFeatures.h>
39 #ifdef VISP_HAVE_MODULE_VISUAL_FEATURES
45 : maxSize(0), totalSize(0), vvsIterMax(200), lambda(1.0), verbose(false), computeCovariance(false),
46 covarianceMatrix(), featurePoint_Point_list(), featurePoint3D_Point_list(), featureVanishingPoint_Point_list(),
47 featureVanishingPoint_DuoLine_list(), featureEllipse_Sphere_list(), featureEllipse_Circle_list(),
48 featureLine_Line_list(), featureLine_DuoLineInt_List(), featureSegment_DuoPoints_list()
65 for(
int i = (
int)featurePoint_Point_list.size()-1 ; i >= 0 ; i--)
66 delete featurePoint_Point_list[(
unsigned int)i].desiredFeature;
67 featurePoint_Point_list.clear();
69 for(
int i = (
int)featurePoint3D_Point_list.size()-1 ; i >= 0 ; i--)
70 delete featurePoint3D_Point_list[(
unsigned int)i].desiredFeature;
71 featurePoint3D_Point_list.clear();
73 for(
int i = (
int)featureVanishingPoint_Point_list.size()-1 ; i >= 0 ; i--)
74 delete featureVanishingPoint_Point_list[(
unsigned int)i].desiredFeature;
75 featureVanishingPoint_Point_list.clear();
77 for(
int i = (
int)featureVanishingPoint_DuoLine_list.size()-1 ; i >= 0 ; i--)
78 delete featureVanishingPoint_DuoLine_list[(
unsigned int)i].desiredFeature;
79 featureVanishingPoint_DuoLine_list.clear();
81 for(
int i = (
int)featureEllipse_Sphere_list.size()-1 ; i >= 0 ; i--)
82 delete featureEllipse_Sphere_list[(
unsigned int)i].desiredFeature;
83 featureEllipse_Sphere_list.clear();
85 for(
int i = (
int)featureEllipse_Circle_list.size()-1 ; i >= 0 ; i--)
86 delete featureEllipse_Circle_list[(
unsigned int)i].desiredFeature;
87 featureEllipse_Circle_list.clear();
89 for(
int i = (
int)featureLine_Line_list.size()-1 ; i >= 0 ; i--)
90 delete featureLine_Line_list[(
unsigned int)i].desiredFeature;
91 featureLine_Line_list.clear();
93 for(
int i = (
int)featureLine_DuoLineInt_List.size()-1 ; i >= 0 ; i--)
94 delete featureLine_DuoLineInt_List[(
unsigned int)i].desiredFeature;
95 featureLine_DuoLineInt_List.clear();
97 for(
int i = (
int)featureSegment_DuoPoints_list.size()-1 ; i >= 0 ; i--)
98 delete featureSegment_DuoPoints_list[(
unsigned int)i].desiredFeature;
99 featureSegment_DuoPoints_list.clear();
101 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
102 for(
int i = (
int)featureSpecific_list.size()-1 ; i >= 0 ; i--)
103 delete featureSpecific_list[(
unsigned int)i];
104 featureSpecific_list.clear();
118 featurePoint_Point_list.push_back(vpDuo<vpFeaturePoint,vpPoint>());
119 featurePoint_Point_list.back().firstParam = p;
120 featurePoint_Point_list.back().desiredFeature =
new vpFeaturePoint();
124 if(featurePoint_Point_list.size() > maxSize)
125 maxSize = (
unsigned int)featurePoint_Point_list.size();
135 featurePoint3D_Point_list.push_back(vpDuo<vpFeaturePoint3D,vpPoint>());
136 featurePoint3D_Point_list.back().firstParam = p;
141 if(featurePoint3D_Point_list.size() > maxSize)
142 maxSize = (
unsigned int)featurePoint3D_Point_list.size();
152 featureVanishingPoint_Point_list.push_back(vpDuo<vpFeatureVanishingPoint,vpPoint>());
153 featureVanishingPoint_Point_list.back().firstParam = p;
158 if(featureVanishingPoint_Point_list.size() > maxSize)
159 maxSize = (
unsigned int)featureVanishingPoint_Point_list.size();
170 featureVanishingPoint_DuoLine_list.push_back(vpTrio<vpFeatureVanishingPoint,vpLine,vpLine>());
171 featureVanishingPoint_DuoLine_list.back().firstParam = l1;
172 featureVanishingPoint_DuoLine_list.back().secondParam = l2;
177 if(featureVanishingPoint_DuoLine_list.size() > maxSize)
178 maxSize = (
unsigned int)featureVanishingPoint_DuoLine_list.size();
188 featureEllipse_Sphere_list.push_back(vpDuo<vpFeatureEllipse,vpSphere>());
189 featureEllipse_Sphere_list.back().firstParam = s;
194 if(featureEllipse_Sphere_list.size() > maxSize)
195 maxSize = (
unsigned int)featureEllipse_Sphere_list.size();
205 featureEllipse_Circle_list.push_back(vpDuo<vpFeatureEllipse,vpCircle>());
206 featureEllipse_Circle_list.back().firstParam = c;
211 if(featureEllipse_Circle_list.size() > maxSize)
212 maxSize = (
unsigned int)featureEllipse_Circle_list.size();
222 featureLine_Line_list.push_back(vpDuo<vpFeatureLine,vpLine>());
223 featureLine_Line_list.back().firstParam = l;
224 featureLine_Line_list.back().desiredFeature =
new vpFeatureLine();
228 if(featureLine_Line_list.size() > maxSize)
229 maxSize = (
unsigned int)featureLine_Line_list.size();
241 featureLine_DuoLineInt_List.push_back(vpTrio<vpFeatureLine,vpCylinder,int>());
242 featureLine_DuoLineInt_List.back().firstParam = c;
243 featureLine_DuoLineInt_List.back().secondParam = line;
244 featureLine_DuoLineInt_List.back().desiredFeature =
new vpFeatureLine();
248 if(featureLine_DuoLineInt_List.size() > maxSize)
249 maxSize = (
unsigned int)featureLine_DuoLineInt_List.size();
260 featureSegment_DuoPoints_list.push_back(vpTrio<vpFeatureSegment,vpPoint,vpPoint>());
261 featureSegment_DuoPoints_list.back().firstParam = P1;
262 featureSegment_DuoPoints_list.back().secondParam = P2;
263 featureSegment_DuoPoints_list.back().desiredFeature =
new vpFeatureSegment();
267 if(featureSegment_DuoPoints_list.size() > maxSize)
268 maxSize = (
unsigned int)featureSegment_DuoPoints_list.size();
283 for(
unsigned int i = 0 ; i < maxSize ; i++)
287 if( i < featurePoint_Point_list.size() ){
289 vpPoint p(featurePoint_Point_list[i].firstParam);
292 err.
stack(fp.
error(*(featurePoint_Point_list[i].desiredFeature)));
298 if( i < featurePoint3D_Point_list.size() ){
300 vpPoint p(featurePoint3D_Point_list[i].firstParam);
303 err.
stack(fp3D.
error(*(featurePoint3D_Point_list[i].desiredFeature)));
309 if( i < featureVanishingPoint_Point_list.size() ){
311 vpPoint p(featureVanishingPoint_Point_list[i].firstParam);
314 err.
stack(fvp.
error(*(featureVanishingPoint_Point_list[i].desiredFeature)));
318 if( i < featureVanishingPoint_DuoLine_list.size() ){
320 vpLine l1(featureVanishingPoint_DuoLine_list[i].firstParam);
321 vpLine l2(featureVanishingPoint_DuoLine_list[i].secondParam);
325 err.
stack(fvp.
error(*(featureVanishingPoint_DuoLine_list[i].desiredFeature)));
331 if( i < featureEllipse_Sphere_list.size() ){
333 vpSphere s(featureEllipse_Sphere_list[i].firstParam);
336 err.
stack(fe.
error(*(featureEllipse_Sphere_list[i].desiredFeature)));
340 if( i < featureEllipse_Circle_list.size() ){
342 vpCircle c(featureEllipse_Circle_list[i].firstParam);
345 err.
stack(fe.
error(*(featureEllipse_Circle_list[i].desiredFeature)));
351 if( i < featureLine_Line_list.size() ){
353 vpLine l(featureLine_Line_list[i].firstParam);
356 err.
stack(fl.
error(*(featureLine_Line_list[i].desiredFeature)));
360 if( i < featureLine_DuoLineInt_List.size() ){
362 vpCylinder c(featureLine_DuoLineInt_List[i].firstParam);
365 err.
stack(fl.
error(*(featureLine_DuoLineInt_List[i].desiredFeature)));
371 if( i < featureSegment_DuoPoints_list.size() ){
373 vpPoint p1(featureSegment_DuoPoints_list[i].firstParam);
374 vpPoint p2(featureSegment_DuoPoints_list[i].secondParam);
378 err.
stack(fs.
error(*(featureSegment_DuoPoints_list[i].desiredFeature)));
382 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
384 if( i < featureSpecific_list.size() ){
385 featureSpecific_list[i]->createCurrent(cMo);
386 err.
stack(featureSpecific_list[i]->error());
387 L.
stack(featureSpecific_list[i]->currentInteraction());
414 computePoseRobustVVS(cMo);
437 double residu_1 = 1e8 ;
445 unsigned int iter = 0;
448 while(std::fabs((residu_1 - r)*1e12) > std::numeric_limits<double>::epsilon() )
453 error_and_interaction(cMo,err,L);
464 vpTRACE(
"Rank must be at least 6 ! cMo not computed.");
473 if (iter++>vvsIterMax){
474 vpTRACE(
"Max iteration reached") ;
479 if(computeCovariance)
499 double residu_1 = 1e8 ;
509 robust.setThreshold(0.0000) ;
511 unsigned int iter = 0 ;
514 while(std::fabs((residu_1 - r)*1e12) > std::numeric_limits<double>::epsilon())
519 error_and_interaction(cMo,error,L);
531 for(
unsigned int k=0 ; k < error.
getRows()/2 ; k++)
535 robust.setIteration(0);
539 for (
unsigned int k=0 ; k < error.
getRows()/2 ; k++)
542 W[2*k+1][2*k+1] = w[k] ;
547 (W*L).pseudoInverse(Lp,1e-6) ;
552 vpTRACE(
"Rank must be at least 6 ! cMo not computed.");
558 v = -lambda*Lp*W*error ;
561 if (iter++>vvsIterMax){
562 vpTRACE(
"Max iteration reached") ;
567 if(computeCovariance)
577 #endif //#ifdef VISP_HAVE_MODULE_VISUAL_FEATURES
Implementation of a matrix and operations on matrices.
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
void addFeatureSegment(vpPoint &, vpPoint &)
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
void stack(const double &d)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
Class that defines 2D vanishing point visual feature (Z coordinate in 3D space is infinity)...
void stack(const vpMatrix &A)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void addFeatureVanishingPoint(const vpPoint &)
Class that defines what is a sphere.
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
void addFeaturePoint3D(const vpPoint &)
void addFeaturePoint(const vpPoint &)
Class that defines what is a point.
void addFeatureEllipse(const vpCircle &)
virtual ~vpPoseFeatures()
void computePose(vpHomogeneousMatrix &cMo, const vpPoseFeaturesMethodType &type=VIRTUAL_VS)
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
Class that defines a line in the object frame, the camera frame and the image plane. All the parameters must be set in meter.
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
static double sqr(double x)
Class that defines the 3D point visual feature.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
unsigned int getRows() const
Return the number of rows of the 2D array.
Class that defines what is a cylinder.
Implementation of column vector and the associated operations.
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &v)
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
compute the interaction matrix from a subset a the possible features
Contains an M-Estimator and various influence function.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
Class that defines what is a circle.
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
void addFeatureLine(const vpLine &)
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
compute the interaction matrix from a subset a the possible features
void resize(const unsigned int i, const bool flagNullify=true)