38 #include <visp3/vision/vpPoseFeatures.h> 40 #ifdef VISP_HAVE_MODULE_VISUAL_FEATURES 46 : maxSize(0), totalSize(0), vvsIterMax(200), lambda(1.0), verbose(false), computeCovariance(false),
47 covarianceMatrix(), featurePoint_Point_list(), featurePoint3D_Point_list(), featureVanishingPoint_Point_list(),
48 featureVanishingPoint_DuoLine_list(), featureEllipse_Sphere_list(), featureEllipse_Circle_list(),
49 featureLine_Line_list(), featureLine_DuoLineInt_List(), featureSegment_DuoPoints_list()
63 for (
int i = (
int)featurePoint_Point_list.size() - 1; i >= 0; i--)
64 delete featurePoint_Point_list[(
unsigned int)i].desiredFeature;
65 featurePoint_Point_list.clear();
67 for (
int i = (
int)featurePoint3D_Point_list.size() - 1; i >= 0; i--)
68 delete featurePoint3D_Point_list[(
unsigned int)i].desiredFeature;
69 featurePoint3D_Point_list.clear();
71 for (
int i = (
int)featureVanishingPoint_Point_list.size() - 1; i >= 0; i--)
72 delete featureVanishingPoint_Point_list[(
unsigned int)i].desiredFeature;
73 featureVanishingPoint_Point_list.clear();
75 for (
int i = (
int)featureVanishingPoint_DuoLine_list.size() - 1; i >= 0; i--)
76 delete featureVanishingPoint_DuoLine_list[(
unsigned int)i].desiredFeature;
77 featureVanishingPoint_DuoLine_list.clear();
79 for (
int i = (
int)featureEllipse_Sphere_list.size() - 1; i >= 0; i--)
80 delete featureEllipse_Sphere_list[(
unsigned int)i].desiredFeature;
81 featureEllipse_Sphere_list.clear();
83 for (
int i = (
int)featureEllipse_Circle_list.size() - 1; i >= 0; i--)
84 delete featureEllipse_Circle_list[(
unsigned int)i].desiredFeature;
85 featureEllipse_Circle_list.clear();
87 for (
int i = (
int)featureLine_Line_list.size() - 1; i >= 0; i--)
88 delete featureLine_Line_list[(
unsigned int)i].desiredFeature;
89 featureLine_Line_list.clear();
91 for (
int i = (
int)featureLine_DuoLineInt_List.size() - 1; i >= 0; i--)
92 delete featureLine_DuoLineInt_List[(
unsigned int)i].desiredFeature;
93 featureLine_DuoLineInt_List.clear();
95 for (
int i = (
int)featureSegment_DuoPoints_list.size() - 1; i >= 0; i--)
96 delete featureSegment_DuoPoints_list[(
unsigned int)i].desiredFeature;
97 featureSegment_DuoPoints_list.clear();
99 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 100 for (
int i = (
int)featureSpecific_list.size() - 1; i >= 0; i--)
101 delete featureSpecific_list[(
unsigned int)i];
102 featureSpecific_list.clear();
117 featurePoint_Point_list.push_back(vpDuo<vpFeaturePoint, vpPoint>());
118 featurePoint_Point_list.back().firstParam = p;
119 featurePoint_Point_list.back().desiredFeature =
new vpFeaturePoint();
123 if (featurePoint_Point_list.size() > maxSize)
124 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();
153 featureVanishingPoint_Point_list.push_back(vpDuo<vpFeatureVanishingPoint, vpPoint>());
154 featureVanishingPoint_Point_list.back().firstParam = p;
159 if (featureVanishingPoint_Point_list.size() > maxSize)
160 maxSize = (
unsigned int)featureVanishingPoint_Point_list.size();
172 featureVanishingPoint_DuoLine_list.push_back(vpTrio<vpFeatureVanishingPoint, vpLine, vpLine>());
173 featureVanishingPoint_DuoLine_list.back().firstParam = l1;
174 featureVanishingPoint_DuoLine_list.back().secondParam = l2;
179 if (featureVanishingPoint_DuoLine_list.size() > maxSize)
180 maxSize = (
unsigned int)featureVanishingPoint_DuoLine_list.size();
191 featureEllipse_Sphere_list.push_back(vpDuo<vpFeatureEllipse, vpSphere>());
192 featureEllipse_Sphere_list.back().firstParam = s;
197 if (featureEllipse_Sphere_list.size() > maxSize)
198 maxSize = (
unsigned int)featureEllipse_Sphere_list.size();
209 featureEllipse_Circle_list.push_back(vpDuo<vpFeatureEllipse, vpCircle>());
210 featureEllipse_Circle_list.back().firstParam = c;
215 if (featureEllipse_Circle_list.size() > maxSize)
216 maxSize = (
unsigned int)featureEllipse_Circle_list.size();
227 featureLine_Line_list.push_back(vpDuo<vpFeatureLine, vpLine>());
228 featureLine_Line_list.back().firstParam = l;
229 featureLine_Line_list.back().desiredFeature =
new vpFeatureLine();
233 if (featureLine_Line_list.size() > maxSize)
234 maxSize = (
unsigned int)featureLine_Line_list.size();
247 featureLine_DuoLineInt_List.push_back(vpTrio<vpFeatureLine, vpCylinder, int>());
248 featureLine_DuoLineInt_List.back().firstParam = c;
249 featureLine_DuoLineInt_List.back().secondParam = line;
250 featureLine_DuoLineInt_List.back().desiredFeature =
new vpFeatureLine();
254 if (featureLine_DuoLineInt_List.size() > maxSize)
255 maxSize = (
unsigned int)featureLine_DuoLineInt_List.size();
267 featureSegment_DuoPoints_list.push_back(vpTrio<vpFeatureSegment, vpPoint, vpPoint>());
268 featureSegment_DuoPoints_list.back().firstParam = P1;
269 featureSegment_DuoPoints_list.back().secondParam = P2;
270 featureSegment_DuoPoints_list.back().desiredFeature =
new vpFeatureSegment();
274 if (featureSegment_DuoPoints_list.size() > maxSize)
275 maxSize = (
unsigned int)featureSegment_DuoPoints_list.size();
290 for (
unsigned int i = 0; i < maxSize; i++) {
293 if (i < featurePoint_Point_list.size()) {
295 vpPoint p(featurePoint_Point_list[i].firstParam);
298 err.
stack(fp.
error(*(featurePoint_Point_list[i].desiredFeature)));
304 if (i < featurePoint3D_Point_list.size()) {
306 vpPoint p(featurePoint3D_Point_list[i].firstParam);
309 err.
stack(fp3D.
error(*(featurePoint3D_Point_list[i].desiredFeature)));
315 if (i < featureVanishingPoint_Point_list.size()) {
317 vpPoint p(featureVanishingPoint_Point_list[i].firstParam);
320 err.
stack(fvp.
error(*(featureVanishingPoint_Point_list[i].desiredFeature)));
324 if (i < featureVanishingPoint_DuoLine_list.size()) {
326 vpLine l1(featureVanishingPoint_DuoLine_list[i].firstParam);
327 vpLine l2(featureVanishingPoint_DuoLine_list[i].secondParam);
331 err.
stack(fvp.
error(*(featureVanishingPoint_DuoLine_list[i].desiredFeature)));
337 if (i < featureEllipse_Sphere_list.size()) {
339 vpSphere s(featureEllipse_Sphere_list[i].firstParam);
342 err.
stack(fe.
error(*(featureEllipse_Sphere_list[i].desiredFeature)));
346 if (i < featureEllipse_Circle_list.size()) {
348 vpCircle c(featureEllipse_Circle_list[i].firstParam);
351 err.
stack(fe.
error(*(featureEllipse_Circle_list[i].desiredFeature)));
357 if (i < featureLine_Line_list.size()) {
359 vpLine l(featureLine_Line_list[i].firstParam);
362 err.
stack(fl.
error(*(featureLine_Line_list[i].desiredFeature)));
366 if (i < featureLine_DuoLineInt_List.size()) {
368 vpCylinder c(featureLine_DuoLineInt_List[i].firstParam);
371 err.
stack(fl.
error(*(featureLine_DuoLineInt_List[i].desiredFeature)));
377 if (i < featureSegment_DuoPoints_list.size()) {
379 vpPoint p1(featureSegment_DuoPoints_list[i].firstParam);
380 vpPoint p2(featureSegment_DuoPoints_list[i].secondParam);
384 err.
stack(fs.
error(*(featureSegment_DuoPoints_list[i].desiredFeature)));
388 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 390 if (i < featureSpecific_list.size()) {
391 featureSpecific_list[i]->createCurrent(cMo);
392 err.
stack(featureSpecific_list[i]->error());
393 L.
stack(featureSpecific_list[i]->currentInteraction());
420 computePoseRobustVVS(cMo);
442 double residu_1 = 1e8;
449 unsigned int rank_max = 0;
450 unsigned int iter = 0;
453 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
457 error_and_interaction(cMo, err, L);
470 v = -lambda * Lp * err;
473 if (iter++ > vvsIterMax) {
474 vpTRACE(
"Max iteration reached");
480 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
484 if (computeCovariance)
502 double residu_1 = 1e8;
514 unsigned int rank_max = 0;
515 unsigned int iter = 0;
518 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
522 error_and_interaction(cMo, error, L);
534 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
540 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
541 W[2 * k][2 * k] = w[k];
542 W[2 * k + 1][2 * k + 1] = w[k];
547 (W * L).pseudoInverse(Lp, 1e-6);
554 v = -lambda * Lp * W * error;
557 if (iter++ > vvsIterMax) {
558 vpTRACE(
"Max iteration reached");
565 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
569 if (computeCovariance)
580 #endif //#ifdef VISP_HAVE_MODULE_VISUAL_FEATURES Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
void addFeatureSegment(vpPoint &, vpPoint &)
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void stack(const vpMatrix &A)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
compute the interaction matrix from a subset a the possible features
unsigned int getRows() const
void track(const vpHomogeneousMatrix &cMo)
vpHomogeneousMatrix inverse() const
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void addFeatureVanishingPoint(const vpPoint &)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=(selectX()|selectY()))
vpMatrix interaction(unsigned int select=(selectX()|selectY()))
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &x, const vpColVector &b)
void addFeaturePoint3D(const vpPoint &)
void addFeaturePoint(const vpPoint &)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void addFeatureEllipse(const vpCircle &)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
virtual ~vpPoseFeatures()
void computePose(vpHomogeneousMatrix &cMo, const vpPoseFeaturesMethodType &type=VIRTUAL_VS)
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
vpMatrix interaction(unsigned int select=FEATURE_ALL)
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
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 ...
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
void resize(unsigned int i, bool flagNullify=true)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Implementation of column vector and the associated operations.
static vpHomogeneousMatrix direct(const vpColVector &v)
Contains an M-estimator and various influence function.
Tukey influence function.
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setMinMedianAbsoluteDeviation(double mad_min)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
void addFeatureLine(const vpLine &)