33 #include <visp3/vision/vpPoseFeatures.h>
35 #ifdef VISP_HAVE_MODULE_VISUAL_FEATURES
41 : maxSize(0), totalSize(0), vvsIterMax(200), lambda(1.0), verbose(false), computeCovariance(false),
42 covarianceMatrix(), featurePoint_Point_list(), featurePoint3D_Point_list(), featureVanishingPoint_Point_list(),
43 featureVanishingPoint_DuoLine_list(), featureEllipse_Sphere_list(), featureEllipse_Circle_list(),
44 featureLine_Line_list(), featureLine_DuoLineInt_List(), featureSegment_DuoPoints_list()
58 for (
int i = (
int)featurePoint_Point_list.size() - 1; i >= 0; i--)
59 delete featurePoint_Point_list[(
unsigned int)i].desiredFeature;
60 featurePoint_Point_list.clear();
62 for (
int i = (
int)featurePoint3D_Point_list.size() - 1; i >= 0; i--)
63 delete featurePoint3D_Point_list[(
unsigned int)i].desiredFeature;
64 featurePoint3D_Point_list.clear();
66 for (
int i = (
int)featureVanishingPoint_Point_list.size() - 1; i >= 0; i--)
67 delete featureVanishingPoint_Point_list[(
unsigned int)i].desiredFeature;
68 featureVanishingPoint_Point_list.clear();
70 for (
int i = (
int)featureVanishingPoint_DuoLine_list.size() - 1; i >= 0; i--)
71 delete featureVanishingPoint_DuoLine_list[(
unsigned int)i].desiredFeature;
72 featureVanishingPoint_DuoLine_list.clear();
74 for (
int i = (
int)featureEllipse_Sphere_list.size() - 1; i >= 0; i--)
75 delete featureEllipse_Sphere_list[(
unsigned int)i].desiredFeature;
76 featureEllipse_Sphere_list.clear();
78 for (
int i = (
int)featureEllipse_Circle_list.size() - 1; i >= 0; i--)
79 delete featureEllipse_Circle_list[(
unsigned int)i].desiredFeature;
80 featureEllipse_Circle_list.clear();
82 for (
int i = (
int)featureLine_Line_list.size() - 1; i >= 0; i--)
83 delete featureLine_Line_list[(
unsigned int)i].desiredFeature;
84 featureLine_Line_list.clear();
86 for (
int i = (
int)featureLine_DuoLineInt_List.size() - 1; i >= 0; i--)
87 delete featureLine_DuoLineInt_List[(
unsigned int)i].desiredFeature;
88 featureLine_DuoLineInt_List.clear();
90 for (
int i = (
int)featureSegment_DuoPoints_list.size() - 1; i >= 0; i--)
91 delete featureSegment_DuoPoints_list[(
unsigned int)i].desiredFeature;
92 featureSegment_DuoPoints_list.clear();
94 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
95 for (
int i = (
int)featureSpecific_list.size() - 1; i >= 0; i--)
96 delete featureSpecific_list[(
unsigned int)i];
97 featureSpecific_list.clear();
112 featurePoint_Point_list.push_back(vpDuo<vpFeaturePoint, vpPoint>());
113 featurePoint_Point_list.back().firstParam = p;
114 featurePoint_Point_list.back().desiredFeature =
new vpFeaturePoint();
118 if (featurePoint_Point_list.size() > maxSize)
119 maxSize = (
unsigned int)featurePoint_Point_list.size();
130 featurePoint3D_Point_list.push_back(vpDuo<vpFeaturePoint3D, vpPoint>());
131 featurePoint3D_Point_list.back().firstParam = p;
136 if (featurePoint3D_Point_list.size() > maxSize)
137 maxSize = (
unsigned int)featurePoint3D_Point_list.size();
148 featureVanishingPoint_Point_list.push_back(vpDuo<vpFeatureVanishingPoint, vpPoint>());
149 featureVanishingPoint_Point_list.back().firstParam = p;
154 if (featureVanishingPoint_Point_list.size() > maxSize)
155 maxSize = (
unsigned int)featureVanishingPoint_Point_list.size();
167 featureVanishingPoint_DuoLine_list.push_back(vpTrio<vpFeatureVanishingPoint, vpLine, vpLine>());
168 featureVanishingPoint_DuoLine_list.back().firstParam = l1;
169 featureVanishingPoint_DuoLine_list.back().secondParam = l2;
174 if (featureVanishingPoint_DuoLine_list.size() > maxSize)
175 maxSize = (
unsigned int)featureVanishingPoint_DuoLine_list.size();
186 featureEllipse_Sphere_list.push_back(vpDuo<vpFeatureEllipse, vpSphere>());
187 featureEllipse_Sphere_list.back().firstParam = s;
192 if (featureEllipse_Sphere_list.size() > maxSize)
193 maxSize = (
unsigned int)featureEllipse_Sphere_list.size();
204 featureEllipse_Circle_list.push_back(vpDuo<vpFeatureEllipse, vpCircle>());
205 featureEllipse_Circle_list.back().firstParam = c;
210 if (featureEllipse_Circle_list.size() > maxSize)
211 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();
242 featureLine_DuoLineInt_List.push_back(vpTrio<vpFeatureLine, vpCylinder, int>());
243 featureLine_DuoLineInt_List.back().firstParam = c;
244 featureLine_DuoLineInt_List.back().secondParam = line;
245 featureLine_DuoLineInt_List.back().desiredFeature =
new vpFeatureLine();
249 if (featureLine_DuoLineInt_List.size() > maxSize)
250 maxSize = (
unsigned int)featureLine_DuoLineInt_List.size();
262 featureSegment_DuoPoints_list.push_back(vpTrio<vpFeatureSegment, vpPoint, vpPoint>());
263 featureSegment_DuoPoints_list.back().firstParam = P1;
264 featureSegment_DuoPoints_list.back().secondParam = P2;
265 featureSegment_DuoPoints_list.back().desiredFeature =
new vpFeatureSegment();
269 if (featureSegment_DuoPoints_list.size() > maxSize)
270 maxSize = (
unsigned int)featureSegment_DuoPoints_list.size();
285 for (
unsigned int i = 0; i < maxSize; i++) {
288 if (i < featurePoint_Point_list.size()) {
290 vpPoint p(featurePoint_Point_list[i].firstParam);
293 err.
stack(fp.
error(*(featurePoint_Point_list[i].desiredFeature)));
299 if (i < featurePoint3D_Point_list.size()) {
301 vpPoint p(featurePoint3D_Point_list[i].firstParam);
304 err.
stack(fp3D.
error(*(featurePoint3D_Point_list[i].desiredFeature)));
310 if (i < featureVanishingPoint_Point_list.size()) {
312 vpPoint p(featureVanishingPoint_Point_list[i].firstParam);
315 err.
stack(fvp.
error(*(featureVanishingPoint_Point_list[i].desiredFeature)));
319 if (i < featureVanishingPoint_DuoLine_list.size()) {
321 vpLine l1(featureVanishingPoint_DuoLine_list[i].firstParam);
322 vpLine l2(featureVanishingPoint_DuoLine_list[i].secondParam);
326 err.
stack(fvp.
error(*(featureVanishingPoint_DuoLine_list[i].desiredFeature)));
332 if (i < featureEllipse_Sphere_list.size()) {
334 vpSphere s(featureEllipse_Sphere_list[i].firstParam);
337 err.
stack(fe.
error(*(featureEllipse_Sphere_list[i].desiredFeature)));
341 if (i < featureEllipse_Circle_list.size()) {
343 vpCircle c(featureEllipse_Circle_list[i].firstParam);
346 err.
stack(fe.
error(*(featureEllipse_Circle_list[i].desiredFeature)));
352 if (i < featureLine_Line_list.size()) {
354 vpLine l(featureLine_Line_list[i].firstParam);
357 err.
stack(fl.
error(*(featureLine_Line_list[i].desiredFeature)));
361 if (i < featureLine_DuoLineInt_List.size()) {
363 vpCylinder c(featureLine_DuoLineInt_List[i].firstParam);
366 err.
stack(fl.
error(*(featureLine_DuoLineInt_List[i].desiredFeature)));
372 if (i < featureSegment_DuoPoints_list.size()) {
374 vpPoint p1(featureSegment_DuoPoints_list[i].firstParam);
375 vpPoint p2(featureSegment_DuoPoints_list[i].secondParam);
379 err.
stack(fs.
error(*(featureSegment_DuoPoints_list[i].desiredFeature)));
383 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
385 if (i < featureSpecific_list.size()) {
386 featureSpecific_list[i]->createCurrent(cMo);
387 err.
stack(featureSpecific_list[i]->error());
388 L.stack(featureSpecific_list[i]->currentInteraction());
415 computePoseRobustVVS(cMo);
437 double residu_1 = 1e8;
444 unsigned int rank_max = 0;
445 unsigned int iter = 0;
448 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
452 error_and_interaction(cMo, err, L);
459 unsigned int rank = L.pseudoInverse(Lp, 1e-6);
465 v = -lambda * Lp * err;
468 if (iter++ > vvsIterMax) {
469 vpTRACE(
"Max iteration reached");
475 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
479 if (computeCovariance)
497 double residu_1 = 1e8;
509 unsigned int rank_max = 0;
510 unsigned int iter = 0;
513 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
517 error_and_interaction(cMo, error, L);
529 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
535 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
536 W[2 * k][2 * k] = w[k];
537 W[2 * k + 1][2 * k + 1] = w[k];
542 (W * L).pseudoInverse(Lp, 1e-6);
543 unsigned int rank = L.pseudoInverse(LRank, 1e-6);
549 v = -lambda * Lp * W * error;
552 if (iter++ > vvsIterMax) {
553 vpTRACE(
"Max iteration reached");
560 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
564 if (computeCovariance)
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
static vpHomogeneousMatrix direct(const vpColVector &v)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines 2D ellipse visual feature.
vpMatrix interaction(unsigned int select=FEATURE_ALL)
compute the interaction matrix from a subset a the possible features
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
vpMatrix interaction(unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Class that defines the 3D point visual feature.
vpMatrix interaction(unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
vpMatrix interaction(unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=(selectX()|selectY()))
vpMatrix interaction(unsigned int select=(selectX()|selectY()))
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
static double sqr(double x)
Implementation of a matrix and operations on matrices.
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void addFeatureVanishingPoint(const vpPoint &)
void addFeaturePoint3D(const vpPoint &)
void addFeatureLine(const vpLine &)
void addFeaturePoint(const vpPoint &)
virtual ~vpPoseFeatures()
void addFeatureEllipse(const vpCircle &)
void computePose(vpHomogeneousMatrix &cMo, const vpPoseFeaturesMethodType &type=VIRTUAL_VS)
void addFeatureSegment(vpPoint &, vpPoint &)
Contains an M-estimator and various influence function.
@ TUKEY
Tukey influence function.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
void setMinMedianAbsoluteDeviation(double mad_min)
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...