39 #include <visp3/core/vpConfig.h>
40 #include <visp3/core/vpExponentialMap.h>
41 #include <visp3/core/vpPoint.h>
42 #include <visp3/core/vpRobust.h>
43 #include <visp3/vision/vpPose.h>
50 double residu_1 = 1e8;
52 const unsigned int index_0 = 0;
53 const unsigned int index_1 = 1;
54 const unsigned int index_2 = 2;
55 const unsigned int index_3 = 3;
56 const unsigned int index_4 = 4;
57 const unsigned int index_5 = 5;
58 const unsigned int dim2DPoints = 2;
64 unsigned int nb =
static_cast<unsigned int>(
listP.size());
65 const unsigned int nbColsL = 6;
66 vpMatrix L(dim2DPoints * nb, nbColsL);
68 vpColVector sd(dim2DPoints * nb), s(dim2DPoints * nb);
72 std::list<vpPoint> lP;
76 std::list<vpPoint>::const_iterator listp_end =
listP.end();
77 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it != listp_end; ++it) {
79 sd[dim2DPoints * k] = P.
get_x();
80 sd[(dim2DPoints * k) + 1] = P.
get_y();
91 bool iter_gt_vvsitermax =
false;
92 while ((std::fabs(residu_1 - r) > vvsEpsilon) && (iter_gt_vvsitermax ==
false)) {
97 std::list<vpPoint>::const_iterator lp_end = lP.end();
98 for (std::list<vpPoint>::const_iterator it = lP.begin(); it != lp_end; ++it) {
105 double x = s[dim2DPoints * k] = P.
get_x();
106 double y = s[(dim2DPoints * k) + index_1] = P.
get_y();
107 double Z = P.
get_Z();
108 L[dim2DPoints * k][index_0] = -1 / Z;
109 L[dim2DPoints * k][index_1] = 0;
110 L[dim2DPoints * k][index_2] = x / Z;
111 L[dim2DPoints * k][index_3] = x * y;
112 L[dim2DPoints * k][index_4] = -(1 + (x * x));
113 L[dim2DPoints * k][index_5] = y;
115 L[(dim2DPoints * k) + 1][index_0] = 0;
116 L[(dim2DPoints * k) + 1][index_1] = -1 / Z;
117 L[(dim2DPoints * k) + 1][index_2] = y / Z;
118 L[(dim2DPoints * k) + 1][index_3] = 1 + (y * y);
119 L[(dim2DPoints * k) + 1][index_4] = -x * y;
120 L[(dim2DPoints * k) + 1][index_5] = -x;
131 L.pseudoInverse(Lp, 1e-16);
141 if (iter> vvsIterMax) {
142 iter_gt_vvsitermax =
true;
150 if (computeCovariance) {
161 double residu_1 = 1e8;
163 const unsigned int index_0 = 0;
164 const unsigned int index_1 = 1;
165 const unsigned int index_2 = 2;
166 const unsigned int index_3 = 3;
167 const unsigned int index_4 = 4;
168 const unsigned int index_5 = 5;
169 const unsigned int dim2DPoints = 2;
177 unsigned int nb =
static_cast<unsigned int>(
listP.size());
178 const unsigned int nbColsL = 6;
179 vpMatrix L(dim2DPoints * nb, nbColsL);
181 vpColVector sd(dim2DPoints * nb), s(dim2DPoints * nb);
185 std::list<vpPoint> lP;
189 std::list<vpPoint>::const_iterator listp_end =
listP.end();
190 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it != listp_end; ++it) {
192 sd[dim2DPoints * k_] = P.
get_x();
193 sd[(dim2DPoints * k_) + 1] = P.
get_y();
204 bool iter_gt_vvsitermax =
false;
205 while ((std::fabs((residu_1 - r) * 1e12) > std::numeric_limits<double>::epsilon()) && (iter_gt_vvsitermax ==
false)) {
210 std::list<vpPoint>::const_iterator lp_end = lP.end();
211 for (std::list<vpPoint>::const_iterator it = lP.begin(); it != lp_end; ++it) {
218 double x = s[dim2DPoints * k_] = P.
get_x();
219 double y = s[(dim2DPoints * k_) + index_1] = P.
get_y();
220 double Z = P.
get_Z();
221 L[dim2DPoints * k_][index_0] = -1 / Z;
222 L[dim2DPoints * k_][index_1] = 0;
223 L[dim2DPoints * k_][index_2] = x / Z;
224 L[dim2DPoints * k_][index_3] = x * y;
225 L[dim2DPoints * k_][index_4] = -(1 + (x * x));
226 L[dim2DPoints * k_][index_5] = y;
228 L[(dim2DPoints * k_) + index_1][index_0] = 0;
229 L[(dim2DPoints * k_) + index_1][index_1] = -1 / Z;
230 L[(dim2DPoints * k_) + index_1][index_2] = y / Z;
231 L[(dim2DPoints * k_) + index_1][index_3] = 1 + (y * y);
232 L[(dim2DPoints * k_) + index_1][index_4] = -x * y;
233 L[(dim2DPoints * k_) + index_1][index_5] = -x;
242 unsigned int v_error_rows = error.
getRows();
243 const unsigned int nbPts = v_error_rows / dim2DPoints;
244 for (
unsigned int k = 0; k < nbPts; ++k) {
250 unsigned int error_rows = error.
getRows();
251 unsigned int nbErrors = error_rows / dim2DPoints;
252 for (
unsigned int k = 0; k < nbErrors; ++k) {
253 W[dim2DPoints * k][dim2DPoints * k] = w[k];
254 W[(dim2DPoints * k) + 1][(dim2DPoints * k) + 1] = w[k];
258 (W * L).pseudoInverse(Lp, 1e-6);
264 if (iter > vvsIterMax) {
265 iter_gt_vvsitermax =
true;
273 if (computeCovariance) {
282 #if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
283 std::optional<vpHomogeneousMatrix> vpPose::poseVirtualVSWithDepth(
const std::vector<vpPoint> &points,
const vpHomogeneousMatrix &cMo)
285 auto residu_1 { 1e8 }, r { 1e8 - 1 };
286 const auto lambda { 0.9 }, vvsEpsilon { 1e-8 };
287 const unsigned int vvsIterMax { 200 };
288 const unsigned int index_0 = 0;
289 const unsigned int index_1 = 1;
290 const unsigned int index_2 = 2;
291 const unsigned int index_3 = 3;
292 const unsigned int index_4 = 4;
293 const unsigned int index_5 = 5;
295 const unsigned int nb =
static_cast<unsigned int>(points.size());
296 const unsigned int sizePoints = 3;
297 const unsigned int nbColsL = 6;
298 vpMatrix L(sizePoints * nb, nbColsL);
300 vpColVector sd(sizePoints * nb), s(sizePoints * nb);
303 auto v_points_size = points.size();
304 for (
auto i = 0u; i < v_points_size; ++i) {
305 sd[sizePoints * i] = points[i].get_x();
306 sd[(sizePoints * i) + index_1] = points[i].get_y();
307 sd[(sizePoints * i) + index_2] = points[i].get_Z();
312 while (std::fabs(residu_1 - r) > vvsEpsilon) {
316 auto points_size = points.
size();
317 for (
auto i = 0u; i < points_size; ++i) {
322 points.at(i).changeFrame(cMo, cP);
323 points.at(i).projection(cP, p);
325 const auto x = s[sizePoints * i] = p[index_0];
326 const auto y = s[(sizePoints * i) + index_1] = p[index_1];
327 const auto Z = s[(sizePoints * i) + index_2] = cP[index_2];
328 L[sizePoints * i][index_0] = -1. / Z;
329 L[sizePoints * i][index_1] = 0;
330 L[sizePoints * i][index_2] = x / Z;
331 L[sizePoints * i][index_3] = x * y;
332 L[sizePoints * i][index_4] = -(1. +
vpMath::sqr(x));
333 L[sizePoints * i][index_5] = y;
335 L[(sizePoints * i) + index_1][index_0] = 0;
336 L[(sizePoints * i) + index_1][index_1] = -1. / Z;
337 L[(sizePoints * i) + index_1][index_2] = y / Z;
338 L[(sizePoints * i) + index_1][index_3] = 1. +
vpMath::sqr(y);
339 L[(sizePoints * i) + index_1][index_4] = -x * y;
340 L[(sizePoints * i) + index_1][index_5] = -x;
342 L[(sizePoints * i) + index_2][index_0] = 0;
343 L[(sizePoints * i) + index_2][index_1] = 0;
344 L[(sizePoints * i) + index_2][index_2] = -1.;
345 L[(sizePoints * i) + index_2][index_3] = -y * Z;
346 L[(sizePoints * i) + index_2][index_4] = x * Z;
347 L[(sizePoints * i) + index_2][index_5] = -0;
356 L.pseudoInverse(Lp, 1e-16);
359 const auto v = -lambda * Lp * err;
364 if (iter > vvsIterMax) {
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
static vpHomogeneousMatrix direct(const vpColVector &v)
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static double sqr(double x)
Implementation of a matrix and operations on matrices.
static vpMatrix computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const vpColVector &deltaS, const vpMatrix &Ls, const vpMatrix &W)
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 ...
double get_y() const
Get the point y coordinate in the image plane.
double get_x() const
Get the point x coordinate in the image plane.
double get_Z() const
Get the point cZ coordinate in the camera frame.
double m_lambda
Parameters use for the virtual visual servoing approach.
std::list< vpPoint > listP
Array of point (use here class vpPoint)
void poseVirtualVS(vpHomogeneousMatrix &cMo)
void poseVirtualVSrobust(vpHomogeneousMatrix &cMo)
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)