34 #include <visp3/core/vpDebug.h>
35 #include <visp3/vision/vpPoseFeatures.h>
37 #if defined(VISP_HAVE_MODULE_VISUAL_FEATURES) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
41 vpPoseFeatures::vpPoseFeatures()
42 : m_maxSize(0), m_totalSize(0), m_vvsIterMax(200), m_lambda(1.0), m_verbose(false), m_computeCovariance(false),
43 m_covarianceMatrix(), m_featurePoint_Point_list(), m_featurePoint3D_Point_list(), m_featureVanishingPoint_Point_list(),
44 m_featureVanishingPoint_DuoLine_list(), m_featureEllipse_Sphere_list(), m_featureEllipse_Circle_list(),
45 m_featureLine_Line_list(), m_featureLine_DuoLineInt_List(), m_featureSegment_DuoPoints_list()
48 vpPoseFeatures::~vpPoseFeatures() { clear(); }
50 void vpPoseFeatures::clear()
52 for (
int i = (
int)m_featurePoint_Point_list.size() - 1; i >= 0; i--)
53 delete m_featurePoint_Point_list[(
unsigned int)i].desiredFeature;
54 m_featurePoint_Point_list.clear();
56 for (
int i = (
int)m_featurePoint3D_Point_list.size() - 1; i >= 0; i--)
57 delete m_featurePoint3D_Point_list[(
unsigned int)i].desiredFeature;
58 m_featurePoint3D_Point_list.clear();
60 for (
int i = (
int)m_featureVanishingPoint_Point_list.size() - 1; i >= 0; i--)
61 delete m_featureVanishingPoint_Point_list[(
unsigned int)i].desiredFeature;
62 m_featureVanishingPoint_Point_list.clear();
64 for (
int i = (
int)m_featureVanishingPoint_DuoLine_list.size() - 1; i >= 0; i--)
65 delete m_featureVanishingPoint_DuoLine_list[(
unsigned int)i].desiredFeature;
66 m_featureVanishingPoint_DuoLine_list.clear();
68 for (
int i = (
int)m_featureEllipse_Sphere_list.size() - 1; i >= 0; i--)
69 delete m_featureEllipse_Sphere_list[(
unsigned int)i].desiredFeature;
70 m_featureEllipse_Sphere_list.clear();
72 for (
int i = (
int)m_featureEllipse_Circle_list.size() - 1; i >= 0; i--)
73 delete m_featureEllipse_Circle_list[(
unsigned int)i].desiredFeature;
74 m_featureEllipse_Circle_list.clear();
76 for (
int i = (
int)m_featureLine_Line_list.size() - 1; i >= 0; i--)
77 delete m_featureLine_Line_list[(
unsigned int)i].desiredFeature;
78 m_featureLine_Line_list.clear();
80 for (
int i = (
int)m_featureLine_DuoLineInt_List.size() - 1; i >= 0; i--)
81 delete m_featureLine_DuoLineInt_List[(
unsigned int)i].desiredFeature;
82 m_featureLine_DuoLineInt_List.clear();
84 for (
int i = (
int)m_featureSegment_DuoPoints_list.size() - 1; i >= 0; i--)
85 delete m_featureSegment_DuoPoints_list[(
unsigned int)i].desiredFeature;
86 m_featureSegment_DuoPoints_list.clear();
88 for (
int i = (
int)m_featureSpecific_list.size() - 1; i >= 0; i--)
89 delete m_featureSpecific_list[(
unsigned int)i];
90 m_featureSpecific_list.clear();
96 void vpPoseFeatures::addFeaturePoint(
const vpPoint &p)
98 m_featurePoint_Point_list.push_back(vpDuo<vpFeaturePoint, vpPoint>());
99 m_featurePoint_Point_list.back().firstParam = p;
100 m_featurePoint_Point_list.back().desiredFeature =
new vpFeaturePoint();
104 if (m_featurePoint_Point_list.size() > m_maxSize)
105 m_maxSize = (
unsigned int)m_featurePoint_Point_list.size();
108 void vpPoseFeatures::addFeaturePoint3D(
const vpPoint &p)
110 m_featurePoint3D_Point_list.push_back(vpDuo<vpFeaturePoint3D, vpPoint>());
111 m_featurePoint3D_Point_list.back().firstParam = p;
116 if (m_featurePoint3D_Point_list.size() > m_maxSize)
117 m_maxSize = (
unsigned int)m_featurePoint3D_Point_list.size();
120 void vpPoseFeatures::addFeatureVanishingPoint(
const vpPoint &p)
122 m_featureVanishingPoint_Point_list.push_back(vpDuo<vpFeatureVanishingPoint, vpPoint>());
123 m_featureVanishingPoint_Point_list.back().firstParam = p;
128 if (m_featureVanishingPoint_Point_list.size() > m_maxSize)
129 m_maxSize = (
unsigned int)m_featureVanishingPoint_Point_list.size();
132 void vpPoseFeatures::addFeatureVanishingPoint(
const vpLine &l1,
const vpLine &l2)
134 m_featureVanishingPoint_DuoLine_list.push_back(vpTrio<vpFeatureVanishingPoint, vpLine, vpLine>());
135 m_featureVanishingPoint_DuoLine_list.back().firstParam = l1;
136 m_featureVanishingPoint_DuoLine_list.back().secondParam = l2;
141 if (m_featureVanishingPoint_DuoLine_list.size() > m_maxSize)
142 m_maxSize = (
unsigned int)m_featureVanishingPoint_DuoLine_list.size();
145 void vpPoseFeatures::addFeatureEllipse(
const vpSphere &s)
147 m_featureEllipse_Sphere_list.push_back(vpDuo<vpFeatureEllipse, vpSphere>());
148 m_featureEllipse_Sphere_list.back().firstParam = s;
149 m_featureEllipse_Sphere_list.back().desiredFeature =
new vpFeatureEllipse();
153 if (m_featureEllipse_Sphere_list.size() > m_maxSize)
154 m_maxSize = (
unsigned int)m_featureEllipse_Sphere_list.size();
157 void vpPoseFeatures::addFeatureEllipse(
const vpCircle &c)
159 m_featureEllipse_Circle_list.push_back(vpDuo<vpFeatureEllipse, vpCircle>());
160 m_featureEllipse_Circle_list.back().firstParam = c;
161 m_featureEllipse_Circle_list.back().desiredFeature =
new vpFeatureEllipse();
165 if (m_featureEllipse_Circle_list.size() > m_maxSize)
166 m_maxSize = (
unsigned int)m_featureEllipse_Circle_list.size();
169 void vpPoseFeatures::addFeatureLine(
const vpLine &l)
171 m_featureLine_Line_list.push_back(vpDuo<vpFeatureLine, vpLine>());
172 m_featureLine_Line_list.back().firstParam = l;
173 m_featureLine_Line_list.back().desiredFeature =
new vpFeatureLine();
177 if (m_featureLine_Line_list.size() > m_maxSize)
178 m_maxSize = (
unsigned int)m_featureLine_Line_list.size();
181 void vpPoseFeatures::addFeatureLine(
const vpCylinder &c,
const int &line)
183 m_featureLine_DuoLineInt_List.push_back(vpTrio<vpFeatureLine, vpCylinder, int>());
184 m_featureLine_DuoLineInt_List.back().firstParam = c;
185 m_featureLine_DuoLineInt_List.back().secondParam = line;
186 m_featureLine_DuoLineInt_List.back().desiredFeature =
new vpFeatureLine();
190 if (m_featureLine_DuoLineInt_List.size() > m_maxSize)
191 m_maxSize = (
unsigned int)m_featureLine_DuoLineInt_List.size();
196 m_featureSegment_DuoPoints_list.push_back(vpTrio<vpFeatureSegment, vpPoint, vpPoint>());
197 m_featureSegment_DuoPoints_list.back().firstParam = P1;
198 m_featureSegment_DuoPoints_list.back().secondParam = P2;
199 m_featureSegment_DuoPoints_list.back().desiredFeature =
new vpFeatureSegment();
203 if (m_featureSegment_DuoPoints_list.size() > m_maxSize)
204 m_maxSize = (
unsigned int)m_featureSegment_DuoPoints_list.size();
212 for (
unsigned int i = 0; i < m_maxSize; i++) {
215 if (i < m_featurePoint_Point_list.size()) {
217 vpPoint p(m_featurePoint_Point_list[i].firstParam);
220 err.
stack(fp.
error(*(m_featurePoint_Point_list[i].desiredFeature)));
226 if (i < m_featurePoint3D_Point_list.size()) {
228 vpPoint p(m_featurePoint3D_Point_list[i].firstParam);
231 err.
stack(fp3D.
error(*(m_featurePoint3D_Point_list[i].desiredFeature)));
237 if (i < m_featureVanishingPoint_Point_list.size()) {
239 vpPoint p(m_featureVanishingPoint_Point_list[i].firstParam);
242 err.
stack(fvp.
error(*(m_featureVanishingPoint_Point_list[i].desiredFeature)));
246 if (i < m_featureVanishingPoint_DuoLine_list.size()) {
248 vpLine l1(m_featureVanishingPoint_DuoLine_list[i].firstParam);
249 vpLine l2(m_featureVanishingPoint_DuoLine_list[i].secondParam);
253 err.
stack(fvp.
error(*(m_featureVanishingPoint_DuoLine_list[i].desiredFeature)));
259 if (i < m_featureEllipse_Sphere_list.size()) {
261 vpSphere s(m_featureEllipse_Sphere_list[i].firstParam);
264 err.
stack(fe.
error(*(m_featureEllipse_Sphere_list[i].desiredFeature)));
268 if (i < m_featureEllipse_Circle_list.size()) {
270 vpCircle c(m_featureEllipse_Circle_list[i].firstParam);
273 err.
stack(fe.
error(*(m_featureEllipse_Circle_list[i].desiredFeature)));
279 if (i < m_featureLine_Line_list.size()) {
281 vpLine l(m_featureLine_Line_list[i].firstParam);
284 err.
stack(fl.
error(*(m_featureLine_Line_list[i].desiredFeature)));
288 if (i < m_featureLine_DuoLineInt_List.size()) {
290 vpCylinder c(m_featureLine_DuoLineInt_List[i].firstParam);
293 err.
stack(fl.
error(*(m_featureLine_DuoLineInt_List[i].desiredFeature)));
299 if (i < m_featureSegment_DuoPoints_list.size()) {
301 vpPoint p1(m_featureSegment_DuoPoints_list[i].firstParam);
302 vpPoint p2(m_featureSegment_DuoPoints_list[i].secondParam);
306 err.
stack(fs.
error(*(m_featureSegment_DuoPoints_list[i].desiredFeature)));
311 if (i < m_featureSpecific_list.size()) {
312 m_featureSpecific_list[i]->createCurrent(cMo);
313 err.
stack(m_featureSpecific_list[i]->error());
314 L.stack(m_featureSpecific_list[i]->currentInteraction());
319 void vpPoseFeatures::computePose(
vpHomogeneousMatrix &cMo,
const vpPoseFeaturesMethodType &type)
325 case ROBUST_VIRTUAL_VS:
326 computePoseRobustVVS(cMo);
336 double residu_1 = 1e8;
343 unsigned int rank_max = 0;
344 unsigned int iter = 0;
347 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
351 error_and_interaction(cMo, err, L);
358 unsigned int rank = L.pseudoInverse(Lp, 1e-6);
364 v = -m_lambda * Lp * err;
367 if (iter++ > m_vvsIterMax) {
368 vpTRACE(
"Max iteration reached");
374 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
378 if (m_computeCovariance)
383 vpERROR_TRACE(
"vpPoseFeatures::computePoseVVS");
391 double residu_1 = 1e8;
403 unsigned int rank_max = 0;
404 unsigned int iter = 0;
407 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
411 error_and_interaction(cMo, error, L);
423 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
429 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
430 W[2 * k][2 * k] = w[k];
431 W[2 * k + 1][2 * k + 1] = w[k];
436 (W * L).pseudoInverse(Lp, 1e-6);
437 unsigned int rank = L.pseudoInverse(LRank, 1e-6);
443 v = -m_lambda * Lp * W * error;
446 if (iter++ > m_vvsIterMax) {
447 vpTRACE(
"Max iteration reached");
454 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
458 if (m_computeCovariance)
465 vpERROR_TRACE(
"vpPoseFeatures::computePoseRobustVVS");
472 #elif !defined(VISP_BUILD_SHARED_LIBS)
474 void dummy_vpPoseFeatures() { };
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 vpImagePoint &t)
Class that defines 2D ellipse visual feature.
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
compute the interaction matrix from a subset a the possible features
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
Class that defines the 3D point visual feature.
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
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) VP_OVERRIDE
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpColVector error(const vpBasicFeature &s_star, unsigned int select=(vpFeatureVanishingPoint::selectX()|vpFeatureVanishingPoint::selectY())) VP_OVERRIDE
vpMatrix interaction(unsigned int select=(vpFeatureVanishingPoint::selectX()|vpFeatureVanishingPoint::selectY())) VP_OVERRIDE
void track(const vpHomogeneousMatrix &cMo)
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 ...
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...