33 #include <visp3/vision/vpPoseFeatures.h>
35 #ifdef VISP_HAVE_MODULE_VISUAL_FEATURES
38 : m_maxSize(0), m_totalSize(0), m_vvsIterMax(200), m_lambda(1.0), m_verbose(false), m_computeCovariance(false),
39 m_covarianceMatrix(), m_featurePoint_Point_list(), m_featurePoint3D_Point_list(), m_featureVanishingPoint_Point_list(),
40 m_featureVanishingPoint_DuoLine_list(), m_featureEllipse_Sphere_list(), m_featureEllipse_Circle_list(),
41 m_featureLine_Line_list(), m_featureLine_DuoLineInt_List(), m_featureSegment_DuoPoints_list()
48 for (
int i = (
int)m_featurePoint_Point_list.size() - 1; i >= 0; i--)
49 delete m_featurePoint_Point_list[(
unsigned int)i].desiredFeature;
50 m_featurePoint_Point_list.clear();
52 for (
int i = (
int)m_featurePoint3D_Point_list.size() - 1; i >= 0; i--)
53 delete m_featurePoint3D_Point_list[(
unsigned int)i].desiredFeature;
54 m_featurePoint3D_Point_list.clear();
56 for (
int i = (
int)m_featureVanishingPoint_Point_list.size() - 1; i >= 0; i--)
57 delete m_featureVanishingPoint_Point_list[(
unsigned int)i].desiredFeature;
58 m_featureVanishingPoint_Point_list.clear();
60 for (
int i = (
int)m_featureVanishingPoint_DuoLine_list.size() - 1; i >= 0; i--)
61 delete m_featureVanishingPoint_DuoLine_list[(
unsigned int)i].desiredFeature;
62 m_featureVanishingPoint_DuoLine_list.clear();
64 for (
int i = (
int)m_featureEllipse_Sphere_list.size() - 1; i >= 0; i--)
65 delete m_featureEllipse_Sphere_list[(
unsigned int)i].desiredFeature;
66 m_featureEllipse_Sphere_list.clear();
68 for (
int i = (
int)m_featureEllipse_Circle_list.size() - 1; i >= 0; i--)
69 delete m_featureEllipse_Circle_list[(
unsigned int)i].desiredFeature;
70 m_featureEllipse_Circle_list.clear();
72 for (
int i = (
int)m_featureLine_Line_list.size() - 1; i >= 0; i--)
73 delete m_featureLine_Line_list[(
unsigned int)i].desiredFeature;
74 m_featureLine_Line_list.clear();
76 for (
int i = (
int)m_featureLine_DuoLineInt_List.size() - 1; i >= 0; i--)
77 delete m_featureLine_DuoLineInt_List[(
unsigned int)i].desiredFeature;
78 m_featureLine_DuoLineInt_List.clear();
80 for (
int i = (
int)m_featureSegment_DuoPoints_list.size() - 1; i >= 0; i--)
81 delete m_featureSegment_DuoPoints_list[(
unsigned int)i].desiredFeature;
82 m_featureSegment_DuoPoints_list.clear();
84 for (
int i = (
int)m_featureSpecific_list.size() - 1; i >= 0; i--)
85 delete m_featureSpecific_list[(
unsigned int)i];
86 m_featureSpecific_list.clear();
94 m_featurePoint_Point_list.push_back(vpDuo<vpFeaturePoint, vpPoint>());
95 m_featurePoint_Point_list.back().firstParam = p;
96 m_featurePoint_Point_list.back().desiredFeature =
new vpFeaturePoint();
100 if (m_featurePoint_Point_list.size() > m_maxSize)
101 m_maxSize = (
unsigned int)m_featurePoint_Point_list.size();
106 m_featurePoint3D_Point_list.push_back(vpDuo<vpFeaturePoint3D, vpPoint>());
107 m_featurePoint3D_Point_list.back().firstParam = p;
112 if (m_featurePoint3D_Point_list.size() > m_maxSize)
113 m_maxSize = (
unsigned int)m_featurePoint3D_Point_list.size();
118 m_featureVanishingPoint_Point_list.push_back(vpDuo<vpFeatureVanishingPoint, vpPoint>());
119 m_featureVanishingPoint_Point_list.back().firstParam = p;
124 if (m_featureVanishingPoint_Point_list.size() > m_maxSize)
125 m_maxSize = (
unsigned int)m_featureVanishingPoint_Point_list.size();
130 m_featureVanishingPoint_DuoLine_list.push_back(vpTrio<vpFeatureVanishingPoint, vpLine, vpLine>());
131 m_featureVanishingPoint_DuoLine_list.back().firstParam = l1;
132 m_featureVanishingPoint_DuoLine_list.back().secondParam = l2;
137 if (m_featureVanishingPoint_DuoLine_list.size() > m_maxSize)
138 m_maxSize = (
unsigned int)m_featureVanishingPoint_DuoLine_list.size();
143 m_featureEllipse_Sphere_list.push_back(vpDuo<vpFeatureEllipse, vpSphere>());
144 m_featureEllipse_Sphere_list.back().firstParam = s;
145 m_featureEllipse_Sphere_list.back().desiredFeature =
new vpFeatureEllipse();
149 if (m_featureEllipse_Sphere_list.size() > m_maxSize)
150 m_maxSize = (
unsigned int)m_featureEllipse_Sphere_list.size();
155 m_featureEllipse_Circle_list.push_back(vpDuo<vpFeatureEllipse, vpCircle>());
156 m_featureEllipse_Circle_list.back().firstParam = c;
157 m_featureEllipse_Circle_list.back().desiredFeature =
new vpFeatureEllipse();
161 if (m_featureEllipse_Circle_list.size() > m_maxSize)
162 m_maxSize = (
unsigned int)m_featureEllipse_Circle_list.size();
167 m_featureLine_Line_list.push_back(vpDuo<vpFeatureLine, vpLine>());
168 m_featureLine_Line_list.back().firstParam = l;
169 m_featureLine_Line_list.back().desiredFeature =
new vpFeatureLine();
173 if (m_featureLine_Line_list.size() > m_maxSize)
174 m_maxSize = (
unsigned int)m_featureLine_Line_list.size();
179 m_featureLine_DuoLineInt_List.push_back(vpTrio<vpFeatureLine, vpCylinder, int>());
180 m_featureLine_DuoLineInt_List.back().firstParam = c;
181 m_featureLine_DuoLineInt_List.back().secondParam = line;
182 m_featureLine_DuoLineInt_List.back().desiredFeature =
new vpFeatureLine();
186 if (m_featureLine_DuoLineInt_List.size() > m_maxSize)
187 m_maxSize = (
unsigned int)m_featureLine_DuoLineInt_List.size();
192 m_featureSegment_DuoPoints_list.push_back(vpTrio<vpFeatureSegment, vpPoint, vpPoint>());
193 m_featureSegment_DuoPoints_list.back().firstParam = P1;
194 m_featureSegment_DuoPoints_list.back().secondParam = P2;
195 m_featureSegment_DuoPoints_list.back().desiredFeature =
new vpFeatureSegment();
199 if (m_featureSegment_DuoPoints_list.size() > m_maxSize)
200 m_maxSize = (
unsigned int)m_featureSegment_DuoPoints_list.size();
208 for (
unsigned int i = 0; i < m_maxSize; i++) {
211 if (i < m_featurePoint_Point_list.size()) {
213 vpPoint p(m_featurePoint_Point_list[i].firstParam);
216 err.
stack(fp.
error(*(m_featurePoint_Point_list[i].desiredFeature)));
222 if (i < m_featurePoint3D_Point_list.size()) {
224 vpPoint p(m_featurePoint3D_Point_list[i].firstParam);
227 err.
stack(fp3D.
error(*(m_featurePoint3D_Point_list[i].desiredFeature)));
233 if (i < m_featureVanishingPoint_Point_list.size()) {
235 vpPoint p(m_featureVanishingPoint_Point_list[i].firstParam);
238 err.
stack(fvp.
error(*(m_featureVanishingPoint_Point_list[i].desiredFeature)));
242 if (i < m_featureVanishingPoint_DuoLine_list.size()) {
244 vpLine l1(m_featureVanishingPoint_DuoLine_list[i].firstParam);
245 vpLine l2(m_featureVanishingPoint_DuoLine_list[i].secondParam);
249 err.
stack(fvp.
error(*(m_featureVanishingPoint_DuoLine_list[i].desiredFeature)));
255 if (i < m_featureEllipse_Sphere_list.size()) {
257 vpSphere s(m_featureEllipse_Sphere_list[i].firstParam);
260 err.
stack(fe.
error(*(m_featureEllipse_Sphere_list[i].desiredFeature)));
264 if (i < m_featureEllipse_Circle_list.size()) {
266 vpCircle c(m_featureEllipse_Circle_list[i].firstParam);
269 err.
stack(fe.
error(*(m_featureEllipse_Circle_list[i].desiredFeature)));
275 if (i < m_featureLine_Line_list.size()) {
277 vpLine l(m_featureLine_Line_list[i].firstParam);
280 err.
stack(fl.
error(*(m_featureLine_Line_list[i].desiredFeature)));
284 if (i < m_featureLine_DuoLineInt_List.size()) {
286 vpCylinder c(m_featureLine_DuoLineInt_List[i].firstParam);
289 err.
stack(fl.
error(*(m_featureLine_DuoLineInt_List[i].desiredFeature)));
295 if (i < m_featureSegment_DuoPoints_list.size()) {
297 vpPoint p1(m_featureSegment_DuoPoints_list[i].firstParam);
298 vpPoint p2(m_featureSegment_DuoPoints_list[i].secondParam);
302 err.
stack(fs.
error(*(m_featureSegment_DuoPoints_list[i].desiredFeature)));
307 if (i < m_featureSpecific_list.size()) {
308 m_featureSpecific_list[i]->createCurrent(cMo);
309 err.
stack(m_featureSpecific_list[i]->error());
310 L.stack(m_featureSpecific_list[i]->currentInteraction());
322 computePoseRobustVVS(cMo);
332 double residu_1 = 1e8;
339 unsigned int rank_max = 0;
340 unsigned int iter = 0;
343 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
347 error_and_interaction(cMo, err, L);
354 unsigned int rank = L.pseudoInverse(Lp, 1e-6);
360 v = -m_lambda * Lp * err;
363 if (iter++ > m_vvsIterMax) {
364 vpTRACE(
"Max iteration reached");
370 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
374 if (m_computeCovariance)
387 double residu_1 = 1e8;
399 unsigned int rank_max = 0;
400 unsigned int iter = 0;
403 while (std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) {
407 error_and_interaction(cMo, error, L);
419 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
425 for (
unsigned int k = 0; k < error.
getRows() / 2; k++) {
426 W[2 * k][2 * k] = w[k];
427 W[2 * k + 1][2 * k + 1] = w[k];
432 (W * L).pseudoInverse(Lp, 1e-6);
433 unsigned int rank = L.pseudoInverse(LRank, 1e-6);
439 v = -m_lambda * Lp * W * error;
442 if (iter++ > m_vvsIterMax) {
443 vpTRACE(
"Max iteration reached");
450 vpTRACE(
"Only %d pose parameters can be estimated.", rank_max);
454 if (m_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.
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) override
vpMatrix interaction(unsigned int select=FEATURE_ALL) override
compute the interaction matrix from a subset a the possible features
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) override
vpMatrix interaction(unsigned int select=FEATURE_ALL) override
Class that defines the 3D point visual feature.
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) override
vpMatrix interaction(unsigned int select=FEATURE_ALL) override
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
vpMatrix interaction(unsigned int select=FEATURE_ALL) override
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) override
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) override
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) override
vpColVector error(const vpBasicFeature &s_star, unsigned int select=(selectX()|selectY())) override
vpMatrix interaction(unsigned int select=(selectX()|selectY())) override
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 addFeaturePoint3D(const vpPoint &p)
void addFeaturePoint(const vpPoint &p)
void addFeatureLine(const vpLine &)
virtual ~vpPoseFeatures()
void addFeatureEllipse(const vpCircle &)
void addFeatureVanishingPoint(const vpPoint &p)
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...