30 #include <mrpt/otherlibs/do_opencv_includes.h>
57 const CImage&
img,
const CImage& patch_img,
size_t& x_max,
size_t& y_max,
58 double& max_val,
int x_search_ini,
int y_search_ini,
int x_search_size,
65 CvPoint min_point, max_point;
68 (x_search_ini < 0 || y_search_ini < 0 || x_search_size < 0 ||
82 const_cast<IplImage*
>(
img.getAs<IplImage>()));
84 const_cast<IplImage*
>(patch_img.
getAs<IplImage>()));
89 const int patch_w = patch_im.
getWidth();
94 x_search_size = im_w - patch_w;
95 y_search_size = im_h - patch_h;
99 if ((x_search_ini + x_search_size + patch_w) > im_w)
100 x_search_size -= (x_search_ini + x_search_size + patch_w) - im_w;
102 if ((y_search_ini + y_search_size + patch_h) > im_h)
103 y_search_size -= (y_search_ini + y_search_size + patch_h) - im_h;
105 ASSERT_((x_search_ini + x_search_size + patch_w) <= im_w);
106 ASSERT_((y_search_ini + y_search_size + patch_h) <= im_h);
107 IplImage* result = cvCreateImage(
108 cvSize(x_search_size + 1, y_search_size + 1), IPL_DEPTH_32F, 1);
110 CImage img_region_to_search;
120 img_region_to_search,
123 patch_w + x_search_size,
124 patch_h + y_search_size);
129 img_region_to_search.
getAs<IplImage>(), patch_im.
getAs<IplImage>(),
130 result, CV_TM_CCORR_NORMED);
133 cvMinMaxLoc(result, &mini, &max_val, &min_point, &max_point,
nullptr);
134 x_max = max_point.x + x_search_ini + (
mrpt::round(patch_w - 1) >> 1);
135 y_max = max_point.y + y_search_ini + (
mrpt::round(patch_h - 1) >> 1);
138 cvReleaseImage(&result);
141 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
155 cvFlip(
img.getAs<IplImage>());
157 img.setOriginTopLeft(
true);
159 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
173 res.x = xy.
x - A.get_unsafe(0, 2);
174 res.y = xy.
y - A.get_unsafe(1, 2);
175 res.z = A.get_unsafe(0, 0);
178 const double u =
res.norm();
189 const double focalLengthX,
const double focalLengthY,
const double centerX,
190 const double centerY)
194 A(0, 0) = focalLengthX;
195 A(1, 1) = focalLengthY;
208 unsigned int camIndex,
unsigned int resX,
unsigned int resY)
210 float fx, fy, cx, cy;
233 "Unknown camera index!! for 'camIndex'=%u", camIndex);
238 resX * fx, resY * fy, resX * cx, resY * cy);
247 float lx = 0.0, ly = 0.0;
250 for (itList1 = feat_list.
begin(); itList1 != feat_list.
end(); itList1++)
254 for (itList2 = itList1; itList2 != feat_list.
end(); itList2++)
256 if ((lx == (*itList2)->x && ly == (*itList2)->y) &&
257 ((*itList2)->x > 0.0f && (*itList2)->y > 0.0f))
259 (*itList2)->x = -1.0f;
260 (*itList2)->y = -1.0f;
266 for (itList1 = feat_list.
begin(); itList1 != feat_list.
end();)
268 if ((*itList1)->x == -1.0f && (*itList1)->y == -1.0f)
269 itList1 = feat_list.
erase(itList1);
284 std::cout << std::endl
285 <<
"[ROW CHECKING]------------------------------------------"
289 for (itLeft = leftList.
begin(), itRight = rightList.
begin();
290 itLeft != leftList.
end();)
292 if ((*itLeft)->x < 0 || (*itLeft)->y < 0 || (*itRight)->x < 0 ||
293 (*itRight)->y < 0 || fabs((*itLeft)->y - (*itRight)->y) > threshold)
295 std::cout <<
"[Erased Feature] Row Dif: "
296 << fabs((*itLeft)->y - (*itRight)->y) << std::endl;
297 itLeft = leftList.
erase(itLeft);
298 itRight = rightList.
erase(itRight);
307 std::cout <<
"------------------------------------------" << std::endl;
309 std::cout <<
"Tracked features: " << leftList.
size() <<
" and "
310 << rightList.
size() << std::endl;
325 double varx = 0, vary = 0;
327 for (it = list.
begin(); it != list.
end(); it++)
335 for (it = list.
begin(); it != list.
end(); it++)
359 for (it = feat_list.begin(); it != feat_list.end(); it++)
361 err.
x = it->other_x - (it->this_x * mat.get_unsafe(0, 0) +
362 it->this_y * mat.get_unsafe(0, 1) +
363 it->this_z * mat.get_unsafe(0, 2) + Rt.
x());
364 err.
y = it->other_y - (it->this_x * mat.get_unsafe(1, 0) +
365 it->this_y * mat.get_unsafe(1, 1) +
366 it->this_z * mat.get_unsafe(1, 2) + Rt.
y());
367 err.
z = it->other_z - (it->this_x * mat.get_unsafe(2, 0) +
368 it->this_y * mat.get_unsafe(2, 1) +
369 it->this_z * mat.get_unsafe(2, 2) + Rt.z());
374 return (acum / feat_list.size());
391 if (itLand1->ID == itLand2->ID)
396 pair.
this_x = itLand1->pose_mean.x;
397 pair.
this_y = itLand1->pose_mean.y;
398 pair.
this_z = itLand1->pose_mean.z;
400 pair.
other_x = itLand2->pose_mean.x;
401 pair.
other_y = itLand2->pose_mean.y;
402 pair.
other_z = itLand2->pose_mean.z;
404 outList.push_back(pair);
415 float orientation = 0;
416 if ((
int(
x) - 1 >= 0) && (
int(
y) - 1 >= 0) && (
x + 1 <
image.getWidth()) &&
417 (
y + 1 <
image.getHeight()))
418 orientation = (float)atan2(
439 nim.resize(
image.getHeight(),
image.getWidth());
441 image.getAsMatrix(im);
444 im.meanAndStdAll(m,
s);
446 for (
int k1 = 0; k1 < (int)nim.cols(); ++k1)
447 for (
int k2 = 0; k2 < (int)nim.rows(); ++k2)
448 nim.set_unsafe(k2, k1, (im.get_unsafe(k2, k1) - m) /
s);
466 size_t sz1 = list1.
size(), sz2 = list2.
size();
468 ASSERT_((sz1 > 0) && (sz2 > 0));
485 double minSAD1, minSAD2;
487 vector<int> idxLeftList, idxRightList;
490 vector<double> distCorrs(sz1);
492 int minLeftIdx = 0, minRightIdx;
496 for (lFeat = 0, itList1 = list1.
begin(); itList1 != list1.
end();
514 for (rFeat = 0, itList2 = list2.
begin(); itList2 != list2.
end();
522 d = (*itList1)->y - (*itList2)->y;
529 TPoint2D oPoint((*itList2)->x, (*itList2)->y);
532 p(0, 0) = (*itList1)->x;
533 p(1, 0) = (*itList1)->y;
538 epiLine.
coefs[0] = l(0, 0);
539 epiLine.
coefs[1] = l(1, 0);
540 epiLine.
coefs[2] = l(2, 0);
550 ? ((*itList1)->x - (*itList2)->x) > 0
561 (*itList1)->descriptors.hasDescriptorSIFT() &&
562 (*itList2)->descriptors.hasDescriptorSIFT());
566 (*itList1)->descriptorSIFTDistanceTo(*(*itList2));
569 if (distDesc < minDist1)
576 else if (distDesc < minDist2)
589 (*itList1)->patchSize > 0 &&
590 (*itList2)->patchSize > 0);
592 (*itList1)->patch, (*itList2)->patch, u,
v,
res);
602 else if (
res > maxCC2)
612 (*itList1)->descriptors.hasDescriptorSURF() &&
613 (*itList2)->descriptors.hasDescriptorSURF());
617 (*itList1)->descriptorSURFDistanceTo(*(*itList2));
620 if (distDesc < minDist1)
627 else if (distDesc < minDist2)
637 (*itList1)->descriptors.hasDescriptorORB() &&
638 (*itList2)->descriptors.hasDescriptorORB());
640 (*itList1)->descriptorORBDistanceTo(*(*itList2));
643 if (distDesc < minDist1)
650 else if (distDesc < minDist2)
660 (*itList1)->patchSize > 0 &&
661 (*itList2)->patchSize == (*itList1)->patchSize);
664 "MRPT has been compiled without OpenCV");
666 IplImage *aux1, *aux2;
667 if ((*itList1)->patch.isColor() &&
668 (*itList2)->patch.isColor())
670 const IplImage* preAux1 =
671 (*itList1)->patch.getAs<IplImage>();
672 const IplImage* preAux2 =
673 (*itList2)->patch.getAs<IplImage>();
675 aux1 = cvCreateImage(
677 (*itList1)->patch.getHeight(),
678 (*itList1)->patch.getWidth()),
680 aux2 = cvCreateImage(
682 (*itList2)->patch.getHeight(),
683 (*itList2)->patch.getWidth()),
686 cvCvtColor(preAux1, aux1, CV_BGR2GRAY);
687 cvCvtColor(preAux2, aux2, CV_BGR2GRAY);
691 aux1 =
const_cast<IplImage*
>(
692 (*itList1)->patch.getAs<IplImage>());
693 aux2 =
const_cast<IplImage*
>(
694 (*itList2)->patch.getAs<IplImage>());
719 for (
unsigned int ii = 0;
720 ii < (
unsigned int)aux1->height; ++ii)
721 for (
unsigned int jj = 0;
722 jj < (
unsigned int)aux1->width; ++jj)
724 (
double)(aux1->imageData[ii * aux1->widthStep + jj]) -
725 ((
double)(aux2->imageData[ii * aux2->widthStep + jj])));
726 res =
res / (255.0f * aux1->width * aux1->height);
735 else if (
res < minSAD2)
744 bool cond1 =
false, cond2 =
false;
752 cond2 = (minDist1 / minDist2) <
759 cond2 = (maxCC2 / maxCC1) <
769 (minDist1 / minDist2) <
775 cond2 = (minSAD1 / minSAD2) < options.
SAD_RATIO;
790 int auxIdx = idxRightList[minRightIdx];
793 if (distCorrs[auxIdx] > minVal)
803 distCorrs[minLeftIdx] = minVal;
804 idxLeftList[minLeftIdx] = minRightIdx;
805 idxRightList[minRightIdx] = minLeftIdx;
807 distCorrs[auxIdx] = 1.0;
819 idxRightList[minRightIdx] = minLeftIdx;
820 idxLeftList[minLeftIdx] = minRightIdx;
821 distCorrs[minLeftIdx] = minVal;
832 for (
int vCnt = 0; vCnt < (int)idxLeftList.size(); ++vCnt)
836 std::pair<CFeature::Ptr, CFeature::Ptr> thisMatch;
839 double dp1 = -1.0, dp2 = -1.0;
844 list1[vCnt], list2[idxLeftList[vCnt]], p3D,
params);
854 dp1 = sqrt(p3D.
x * p3D.
x + p3D.
y * p3D.
y + p3D.
z * p3D.
z);
857 p3D.
y * p3D.
y + p3D.
z * p3D.
z);
867 thisMatch.first = list1[vCnt];
868 thisMatch.second = list2[idxLeftList[vCnt]];
873 idLeft = thisMatch.first->ID;
874 idRight = thisMatch.second->ID;
878 keep_max(idLeft, thisMatch.first->ID);
881 keep_max(idRight, thisMatch.second->ID);
888 thisMatch.first->initialDepth = dp1;
889 thisMatch.first->p3D = p3D;
891 thisMatch.second->initialDepth = dp2;
892 thisMatch.second->p3D =
897 matches.push_back(thisMatch);
901 return matches.size();
919 int hwsize = (int)(0.5 * wSize);
920 int mx = mask1.
cols(), my = mask1.
rows();
924 for (it = mList.begin(); it != mList.end(); ++it)
926 for (
int ii = -hwsize; ii < hwsize; ++ii)
927 for (
int jj = -hwsize; jj < hwsize; ++jj)
929 idx = (int)(it->first->x) + ii;
930 idy = (int)(it->first->y) + jj;
931 if (idx >= 0 && idy >= 0 && idx < mx && idy < my)
935 for (
int ii = -hwsize; ii < hwsize; ++ii)
936 for (
int jj = -hwsize; jj < hwsize; ++jj)
938 idx = (int)(it->second->x) + ii;
939 idy = (int)(it->second->y) + jj;
940 if (idx >= 0 && idy >= 0 && idx < mx && idy < my)
953 const IplImage* im1 = patch1.
getAs<IplImage>();
954 const IplImage* im2 = patch2.
getAs<IplImage>();
956 ASSERT_(im1->width == im2->width && im1->height == im2->height);
958 for (
unsigned int ii = 0; ii < (
unsigned int)im1->height; ++ii)
959 for (
unsigned int jj = 0; jj < (
unsigned int)im1->width; ++jj)
961 (
double)(im1->imageData[ii * im1->widthStep + jj]) -
962 ((
double)(im2->imageData[ii * im2->widthStep + jj])));
963 return res / (255.0f * im1->width * im1->height);
966 "MRPT compiled without OpenCV, can't compute SAD of images!")
981 (*it)->x - 5, (*it)->y - 5, (*it)->x + 5, (*it)->y + 5,
993 out_points.reserve(matches.size());
995 it != matches.end(); ++it)
997 const double disp = it->first->x - it->second->x;
998 if (disp < 1)
continue;
1001 out_points.push_back(
1015 vP3D.reserve(leftList.
size());
1017 for (it1 = leftList.
begin(), it2 = rightList.
begin(); it1 != leftList.
end();
1023 vP3D.push_back(p3D);
1046 const double f0 = 600;
1047 double nfx1 = leftFeat->x, nfy1 = leftFeat->y,
1048 nfx2 = rightFeat->x;
1050 const double x = leftFeat->x * f0;
1051 const double y = leftFeat->y * f0;
1052 const double xd = rightFeat->x * f0;
1053 const double yd = rightFeat->y * f0;
1055 const double f2 = f0 * f0;
1056 const double p9 = f2 *
params.F.get_unsafe(2, 2);
1058 f2 * (
params.F.get_unsafe(0, 2) *
params.F.get_unsafe(0, 2) +
1059 params.F.get_unsafe(1, 2) *
params.F.get_unsafe(1, 2) +
1060 params.F.get_unsafe(2, 0) *
params.F.get_unsafe(2, 0) +
1061 params.F.get_unsafe(2, 1) *
params.F.get_unsafe(2, 1));
1063 double Jh = (std::numeric_limits<double>::max)();
1076 (xh * xhd + xhd * xt + xh * xtd) *
params.F.get_unsafe(0, 0);
1078 (xh * yhd + yhd * xt + xh * ytd) *
params.F.get_unsafe(0, 1);
1079 const double p3 = (f0 * (xh + xt)) *
params.F.get_unsafe(0, 2);
1081 (yh * xhd + xhd * yt + yh * xtd) *
params.F.get_unsafe(1, 0);
1083 (yh * yhd + yhd * yt + yh * ytd) *
params.F.get_unsafe(1, 1);
1084 const double p6 = (f0 * (yh + yt)) *
params.F.get_unsafe(1, 2);
1085 const double p7 = (f0 * (xhd + xtd)) *
params.F.get_unsafe(2, 0);
1086 const double p8 = (f0 * (yhd + ytd)) *
params.F.get_unsafe(2, 1);
1088 const double udotxi = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
1090 const double Q11 = (xh * xh + xhd * xhd) *
params.F.get_unsafe(0, 0) *
1091 params.F.get_unsafe(0, 0);
1092 const double Q22 = (xh * xh + yhd * yhd) *
params.F.get_unsafe(0, 1) *
1093 params.F.get_unsafe(0, 1);
1094 const double Q44 = (yh * yh + xhd * xhd) *
params.F.get_unsafe(1, 0) *
1095 params.F.get_unsafe(1, 0);
1096 const double Q55 = (yh * yh + yhd * yhd) *
params.F.get_unsafe(1, 1) *
1097 params.F.get_unsafe(1, 1);
1099 xhd * yhd *
params.F.get_unsafe(0, 0) *
params.F.get_unsafe(0, 1);
1101 f0 * xhd *
params.F.get_unsafe(0, 0) *
params.F.get_unsafe(0, 2);
1103 xh * yh *
params.F.get_unsafe(0, 0) *
params.F.get_unsafe(1, 0);
1105 f0 * xh *
params.F.get_unsafe(0, 0) *
params.F.get_unsafe(2, 0);
1107 f0 * yhd *
params.F.get_unsafe(0, 1) *
params.F.get_unsafe(0, 2);
1109 xh * yh *
params.F.get_unsafe(0, 1) *
params.F.get_unsafe(1, 1);
1111 f0 * xh *
params.F.get_unsafe(0, 1) *
params.F.get_unsafe(2, 1);
1113 xhd * yhd *
params.F.get_unsafe(1, 0) *
params.F.get_unsafe(1, 1);
1115 f0 * xhd *
params.F.get_unsafe(1, 0) *
params.F.get_unsafe(1, 2);
1117 f0 * yh *
params.F.get_unsafe(1, 0) *
params.F.get_unsafe(2, 0);
1119 f0 * yhd *
params.F.get_unsafe(1, 1) *
params.F.get_unsafe(1, 2);
1121 f0 * yh *
params.F.get_unsafe(1, 1) *
params.F.get_unsafe(2, 1);
1123 const double udotV0xiu = Q00 + Q11 + Q22 + Q44 + Q55 +
1124 2.0 * (Q12 + Q13 + Q14 + Q17 + Q23 + Q25 +
1125 Q28 + Q45 + Q46 + Q47 + Q56 + Q58);
1127 ASSERT_(fabs(udotV0xiu) > 1e-5);
1129 const double C = udotxi / udotV0xiu;
1132 (
params.F.get_unsafe(0, 0) * xhd +
1133 params.F.get_unsafe(0, 1) * yhd + f0 *
params.F.get_unsafe(0, 2));
1135 (
params.F.get_unsafe(1, 0) * xhd +
1136 params.F.get_unsafe(1, 1) * yhd + f0 *
params.F.get_unsafe(1, 2));
1138 (
params.F.get_unsafe(0, 0) * xh +
params.F.get_unsafe(1, 0) * yh +
1139 f0 *
params.F.get_unsafe(2, 0));
1141 (
params.F.get_unsafe(0, 1) * xh +
params.F.get_unsafe(1, 1) * yh +
1142 f0 *
params.F.get_unsafe(2, 1));
1144 const double Jt = xt * xt + yt * yt + xtd * xtd + ytd * ytd;
1146 if ((std::abs)(Jt - Jh) <= 1e-5)
1165 double disp = nfx1 - nfx2;
1166 double aux =
params.baseline / disp;
1167 p3D.
x = (nfx1 -
params.K(0, 2)) * aux;
1168 p3D.
y = (nfy1 -
params.K(1, 2)) * aux;
1188 for (itList = mfList.begin(); itList != mfList.end();)
1190 float disp = (itList->first->x - itList->second->x);
1192 itList = mfList.erase(
1199 (itList->first->x -
param.K(0, 2)) * ((
param.baseline)) / disp;
1201 (itList->first->y -
param.K(1, 2)) * ((
param.baseline)) / disp;
1202 float z3D = (
param.K(0, 0)) * ((
param.baseline)) / disp;
1205 if ((z3D <
param.minZ) || (z3D >
param.maxZ))
1206 itList = mfList.erase(itList);
1216 norm3D *= -1 / norm3D.
norm();
1220 lm.
ID = itList->first->ID;
1230 switch (
param.uncPropagation)
1235 float c0 =
param.K(0, 2);
1236 float r0 =
param.K(1, 2);
1239 square(itList->first->x - itList->second->x);
1243 square(itList->first->x - c0) /
1246 stdDisp2 * base2 * (itList->first->x - c0) *
1247 (itList->first->y - r0) /
square(disp2);
1249 (itList->first->x - c0) /
1253 square(itList->first->y - r0) /
1256 (itList->first->y - r0) /
1259 stdDisp2 * foc2 * base2 /
square(disp2);
1266 unsigned int Na = 3;
1269 float k =
param.factor_k;
1271 float w0 = k / (Na + k);
1272 float w1 = 1 / (2 * (Na + k));
1278 Pa(0, 0) = Pa(1, 1) = (Na + k) *
square(
param.stdPixel);
1288 B.resize(2 * Na + 1);
1299 meanA[0] = itList->first->x;
1300 meanA[1] = itList->first->y;
1311 for (i = 1; i <= 2 * Na; i++)
1318 myPoint[0] = meanA[0] + vAux[0];
1319 myPoint[1] = meanA[1] + vAux[1];
1320 myPoint[2] = meanA[2] + vAux[2];
1327 myPoint[0] = meanA[0] - vAux[0];
1328 myPoint[1] = meanA[1] - vAux[1];
1329 myPoint[2] = meanA[2] - vAux[2];
1333 x3D = (myPoint[0] -
param.K(0, 2)) *
1334 ((
param.baseline)) / myPoint[2];
1335 y3D = (myPoint[1] -
param.K(1, 2)) *
1336 ((
param.baseline)) / myPoint[2];
1341 meanB.
x = meanB.
x +
w1 * x3D;
1342 meanB.
y = meanB.
y +
w1 * y3D;
1343 meanB.
z = meanB.
z +
w1 * z3D;
1352 for (i = 0; i <= 2 * Na; i++)
1361 v(0, 0) = B[i].x - meanB.
x;
1362 v(1, 0) = B[i].y - meanB.
y;
1363 v(2, 0) = B[i].z - meanB.
z;
1365 Pb = Pb + weight * (
v *
v.transpose());
1381 unsigned int Na = 3;
1384 float a =
param.factor_a;
1385 float b =
param.factor_b;
1386 float k =
param.factor_k;
1388 float lambda =
square(
a) * (Na + k) - Na;
1390 float w0_m = lambda / (Na + lambda);
1391 float w0_c = w0_m + (1 -
square(
a) +
b);
1392 float w1 = 1 / (2 * (Na + lambda));
1398 Pa(0, 0) = Pa(1, 1) =
1409 B.resize(2 * Na + 1);
1420 meanA[0] = itList->first->x;
1421 meanA[1] = itList->first->y;
1425 meanB.
x = w0_m * x3D;
1426 meanB.
y = w0_m * y3D;
1427 meanB.
z = w0_m * z3D;
1432 for (i = 1; i <= 2 * Na; i++)
1439 myPoint = meanA + vAux;
1449 myPoint = meanA - vAux;
1456 x3D = (myPoint[0] -
param.K(0, 2)) *
1457 ((
param.baseline)) / myPoint[2];
1458 y3D = (myPoint[1] -
param.K(1, 2)) *
1459 ((
param.baseline)) / myPoint[2];
1464 meanB.
x = meanB.
x +
w1 * x3D;
1465 meanB.
y = meanB.
y +
w1 * y3D;
1466 meanB.
z = meanB.
z +
w1 * z3D;
1475 for (i = 0; i <= 2 * Na; i++)
1484 v(0, 0) = B[i].x - meanB.
x;
1485 v(1, 0) = B[i].y - meanB.
y;
1486 v(2, 0) = B[i].z - meanB.
z;
1488 Pb = Pb + weight * (
v *
v.transpose());
1529 for (itListL = leftList.
begin(), itListR = rightList.
begin();
1530 itListL != leftList.
end();)
1532 float disp = ((*itListL)->x - (*itListR)->x);
1535 itListL = leftList.
erase(itListL);
1537 itListR = rightList.
erase(itListR);
1544 ((*itListL)->x -
param.K(0, 2)) * ((
param.baseline)) / disp;
1546 ((*itListL)->y -
param.K(1, 2)) * ((
param.baseline)) / disp;
1547 float z3D = (
param.K(0, 0)) * ((
param.baseline)) / disp;
1550 if ((z3D <
param.minZ) || (z3D >
param.maxZ))
1553 leftList.
erase(itListL);
1556 rightList.
erase(itListR);
1567 norm3D *= -1 / norm3D.
norm();
1571 lm.
ID = (*itListL)->ID;
1582 switch (
param.uncPropagation)
1587 float c0 =
param.K(0, 2);
1588 float r0 =
param.K(1, 2);
1590 float disp2 =
square((*itListL)->x - (*itListR)->x);
1594 square((*itListL)->x - c0) /
1597 ((*itListL)->x - c0) *
1598 ((*itListL)->y - r0) /
square(disp2);
1600 ((*itListL)->x - c0) /
square(disp2);
1603 square((*itListL)->y - r0) /
1606 ((*itListL)->y - r0) /
square(disp2);
1608 stdDisp2 * foc2 * base2 /
square(disp2);
1615 unsigned int Na = 3;
1618 float k =
param.factor_k;
1620 float w0 = k / (Na + k);
1621 float w1 = 1 / (2 * (Na + k));
1627 Pa(0, 0) = Pa(1, 1) = (Na + k) *
square(
param.stdPixel);
1637 B.resize(2 * Na + 1);
1648 meanA[0] = (*itListL)->x;
1649 meanA[1] = (*itListL)->y;
1660 for (i = 1; i <= 2 * Na; i++)
1667 myPoint[0] = meanA[0] + vAux[0];
1668 myPoint[1] = meanA[1] + vAux[1];
1669 myPoint[2] = meanA[2] + vAux[2];
1676 myPoint[0] = meanA[0] - vAux[0];
1677 myPoint[1] = meanA[1] - vAux[1];
1678 myPoint[2] = meanA[2] - vAux[2];
1682 x3D = (myPoint[0] -
param.K(0, 2)) *
1683 ((
param.baseline)) / myPoint[2];
1684 y3D = (myPoint[1] -
param.K(1, 2)) *
1685 ((
param.baseline)) / myPoint[2];
1690 meanB.
x = meanB.
x +
w1 * x3D;
1691 meanB.
y = meanB.
y +
w1 * y3D;
1692 meanB.
z = meanB.
z +
w1 * z3D;
1701 for (i = 0; i <= 2 * Na; i++)
1710 v(0, 0) = B[i].x - meanB.
x;
1711 v(1, 0) = B[i].y - meanB.
y;
1712 v(2, 0) = B[i].z - meanB.
z;
1714 Pb = Pb + weight * (
v *
v.transpose());
1730 unsigned int Na = 3;
1733 float a =
param.factor_a;
1734 float b =
param.factor_b;
1735 float k =
param.factor_k;
1737 float lambda =
square(
a) * (Na + k) - Na;
1739 float w0_m = lambda / (Na + lambda);
1740 float w0_c = w0_m + (1 -
square(
a) +
b);
1741 float w1 = 1 / (2 * (Na + lambda));
1747 Pa(0, 0) = Pa(1, 1) =
1758 B.resize(2 * Na + 1);
1769 meanA[0] = (*itListL)->x;
1770 meanA[1] = (*itListL)->y;
1774 meanB.
x = w0_m * x3D;
1775 meanB.
y = w0_m * y3D;
1776 meanB.
z = w0_m * z3D;
1781 for (i = 1; i <= 2 * Na; i++)
1788 myPoint = meanA + vAux;
1798 myPoint = meanA - vAux;
1805 x3D = (myPoint[0] -
param.K(0, 2)) *
1806 ((
param.baseline)) / myPoint[2];
1807 y3D = (myPoint[1] -
param.K(1, 2)) *
1808 ((
param.baseline)) / myPoint[2];
1813 meanB.
x = meanB.
x +
w1 * x3D;
1814 meanB.
y = meanB.
y +
w1 * y3D;
1815 meanB.
z = meanB.
z +
w1 * z3D;
1824 for (i = 0; i <= 2 * Na; i++)
1833 v(0, 0) = B[i].x - meanB.
x;
1834 v(1, 0) = B[i].y - meanB.
y;
1835 v(2, 0) = B[i].z - meanB.
z;
1837 Pb = Pb + weight * (
v *
v.transpose());
1867 const CPose3D& sensorPose,
const vector<double>& sg,
1871 double f = intrinsicParams(0, 0);
1872 double x0 = intrinsicParams(0, 2);
1873 double y0 = intrinsicParams(1, 2);
1874 double b = baseline;
1875 double sg_c2 =
square(sg[0]);
1876 double sg_r2 =
square(sg[1]);
1877 double sg_d2 =
square(sg[2]);
1880 itMatchList != inMatches.end(); itMatchList++)
1882 double x = itMatchList->first->x;
1883 double y = itMatchList->first->y;
1885 double d = itMatchList->first->x - itMatchList->second->x;
1892 double X = (
x - x0) *
b / d;
1893 double Y = (
y - y0) *
b / d;
1894 double Z = f *
b / d;
1905 m.
yaw = atan2(Y, X);
1919 aux.get_unsafe(0, 0) = k * (sg_c2 + sg_d2 *
square(
x - x0) / d2);
1920 aux.get_unsafe(0, 1) = aux.get_unsafe(1, 0) =
1921 k * (sg_d2 * (
x - x0) * (
y - y0) / d2);
1922 aux.get_unsafe(0, 2) = aux.get_unsafe(2, 0) =
1923 k * (sg_d2 * (
x - x0) * f / d2);
1925 aux.get_unsafe(1, 1) = k * (sg_r2 + sg_d2 *
square(
y - y0) / d2);
1926 aux.get_unsafe(1, 2) = aux.get_unsafe(2, 1) =
1927 k * (sg_d2 * (
y - y0) * f / d2);
1929 aux.get_unsafe(2, 2) = k * (sg_d2 *
square(f) / d2);
1955 JG.set_unsafe(0, 0, X / m.
range);
1956 JG.set_unsafe(0, 1, Y / m.
range);
1957 JG.set_unsafe(0, 2, Z / m.
range);
1961 JG.set_unsafe(1, 2, 0);
2002 unsigned int id = 0;
2022 double sg_c2 =
square(sg[0]);
2023 double sg_r2 =
square(sg[1]);
2024 double sg_d2 =
square(sg[2]);
2027 itMatchList != matchList.end(); itMatchList++,
id++)
2029 double x = itMatchList->first->x;
2030 double y = itMatchList->first->y;
2032 double d = itMatchList->first->x - itMatchList->second->x;
2039 double X = (
x - x0) *
b / d;
2040 double Y = (
y - y0) *
b / d;
2041 double Z = f *
b / d;
2054 m.
yaw = atan2(X, Z);
2055 m.
pitch = atan2(Y, Z);
2067 aux.get_unsafe(0, 0) = k * (sg_c2 + sg_d2 *
square(
x - x0) / d2);
2068 aux.get_unsafe(0, 1) = aux.get_unsafe(1, 0) =
2069 k * (sg_d2 * (
x - x0) * (
y - y0) / d2);
2070 aux.get_unsafe(0, 2) = aux.get_unsafe(2, 0) =
2071 k * (sg_d2 * (
x - x0) * f / d2);
2073 aux.get_unsafe(1, 1) = k * (sg_r2 + sg_d2 *
square(
y - y0) / d2);
2074 aux.get_unsafe(1, 2) = aux.get_unsafe(2, 1) =
2075 k * (sg_d2 * (
y - y0) * f / d2);
2077 aux.get_unsafe(2, 2) = k * (sg_d2 *
square(f) / d2);
2103 JG.set_unsafe(0, 0, X / m.
range);
2104 JG.set_unsafe(0, 1, Y / m.
range);
2105 JG.set_unsafe(0, 2, Z / m.
range);
2109 JG.set_unsafe(1, 2, 0);
2158 square(itCloud->pose_mean.x) +
square(itCloud->pose_mean.y) +
2159 square(itCloud->pose_mean.z));
2165 m.
yaw = atan2(itCloud->pose_mean.y, itCloud->pose_mean.x);
2166 m.
pitch = -sin(itCloud->pose_mean.z / m.
range);
2178 const poses::CPose3D& rightCameraPose,
void* outMap1x,
void* outMap1y,
2179 void* outMap2x,
void* outMap2y)
2183 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x211
2185 cv::Mat *mapx1, *mapy1, *mapx2, *mapy2;
2186 mapx1 =
static_cast<cv::Mat*
>(outMap1x);
2187 mapy1 =
static_cast<cv::Mat*
>(outMap1y);
2188 mapx2 =
static_cast<cv::Mat*
>(outMap2x);
2189 mapy2 =
static_cast<cv::Mat*
>(outMap2y);
2191 const int resX = cam1.
ncols;
2192 const int resY = cam1.
nrows;
2198 rcTrans[0] = hMatrix(0, 3);
2199 rcTrans[1] = hMatrix(1, 3);
2200 rcTrans[2] = hMatrix(2, 3);
2203 for (
unsigned int i = 0; i < 3; ++i)
2204 for (
unsigned int j = 0; j < 3; ++j) m1[i][j] = hMatrix(i, j);
2206 double ipl[3][3], ipr[3][3], dpl[5], dpr[5];
2207 for (
unsigned int i = 0; i < 3; ++i)
2208 for (
unsigned int j = 0; j < 3; ++j)
2214 for (
unsigned int i = 0; i < 5; ++i)
2216 dpl[i] = cam1.
dist[i];
2217 dpr[i] = cam2.
dist[i];
2220 cv::Mat
R(3, 3, CV_64F, &m1);
2221 cv::Mat T(3, 1, CV_64F, &rcTrans);
2223 cv::Mat K1(3, 3, CV_64F, ipl);
2224 cv::Mat K2(3, 3, CV_64F, ipr);
2225 cv::Mat D1(1, 5, CV_64F, dpl);
2226 cv::Mat D2(1, 5, CV_64F, dpr);
2228 double _R1[3][3], _R2[3][3], _P1[3][4], _P2[3][4], _Q[4][4];
2229 cv::Mat R1(3, 3, CV_64F, _R1);
2230 cv::Mat R2(3, 3, CV_64F, _R2);
2231 cv::Mat P1(3, 4, CV_64F, _P1);
2232 cv::Mat P2(3, 4, CV_64F, _P2);
2233 cv::Mat Q(4, 4, CV_64F, _Q);
2235 cv::Size nSize(resX, resY);
2239 #if MRPT_OPENCV_VERSION_NUM < 0x210
2242 K1, D1, K2, D2, nSize,
R, T, R1, R2, P1, P2, Q,
2243 cv::CALIB_ZERO_DISPARITY);
2244 #elif MRPT_OPENCV_VERSION_NUM < 0x230
2247 K1, D1, K2, D2, nSize,
R, T, R1, R2, P1, P2, Q,
alpha,
2250 cv::CALIB_ZERO_DISPARITY);
2254 K1, D1, K2, D2, nSize,
R, T, R1, R2, P1, P2, Q,
2255 cv::CALIB_ZERO_DISPARITY,
alpha);
2260 cv::initUndistortRectifyMap(
2261 K1, D1, R1, P1, cv::Size(resX, resY), CV_32FC1, *mapx1, *mapy1);
2262 cv::initUndistortRectifyMap(
2263 K2, D2, R2, P2, cv::Size(resX, resY), CV_32FC1, *mapx2, *mapy2);
2267 "The MRPT has been compiled with MRPT_HAS_OPENCV = 0 or OpenCV version "
2277 : xMin(x1), xMax(x2), yMin(y1), yMax(y2), zMin(z1), zMax(z2)
2286 : xMin(x1), xMax(x2), yMin(y1), yMax(y2)
2294 : uncPropagation(Prop_Linear),
2307 F.set_unsafe(1, 2, -1);
2308 F.set_unsafe(2, 1, 1);
2335 for (
unsigned int ii = 0; ii < 3; ++ii)
2336 for (
unsigned int jj = 0; jj < 3; ++jj)
K(ii, jj) = k_vec[ii * 3 + jj];
2341 for (
unsigned int ii = 0; ii < 3; ++ii)
2342 for (
unsigned int jj = 0; jj < 3; ++jj)
F(ii, jj) = f_vec[ii * 3 + jj];
2361 "\n----------- [vision::TStereoSystemParams] ------------ \n");
2376 out <<
mrpt::format(
"K\t\t\t= [%f\t%f\t%f]\n",
K(0, 0),
K(0, 1),
K(0, 2));
2377 out <<
mrpt::format(
" \t\t\t [%f\t%f\t%f]\n",
K(1, 0),
K(1, 1),
K(1, 2));
2378 out <<
mrpt::format(
" \t\t\t [%f\t%f\t%f]\n",
K(2, 0),
K(2, 1),
K(2, 2));
2380 out <<
mrpt::format(
"F\t\t\t= [%f\t%f\t%f]\n",
F(0, 0),
F(0, 1),
F(0, 2));
2381 out <<
mrpt::format(
" \t\t\t [%f\t%f\t%f]\n",
F(1, 0),
F(1, 1),
F(1, 2));
2382 out <<
mrpt::format(
" \t\t\t [%f\t%f\t%f]\n",
F(2, 0),
F(2, 1),
F(2, 2));
2395 "-------------------------------------------------------- \n");
2403 useEpipolarRestriction(true),
2406 hasFundamentalMatrix(
2408 parallelOpticalAxis(true),
2411 useXRestriction(true),
2415 useDisparityLimits(false),
2420 matching_method(mmCorrelation),
2442 estimateDepth(false),
2443 maxDepthThreshold(15.0)
2520 "\n----------- [vision::TMatchingOptions] ------------ \n");
2527 "Ā· Min. CC. Threshold: %f\n",
minCC_TH);
2529 "Ā· Min. Dif. CC Threshold: %f\n",
minDCC_TH);
2535 "Ā· Max. EDD Threshold: %f\n",
maxEDD_TH);
2549 "Ā· Max. Dif. SAD Threshold: %f\n",
maxSAD_TH);
2551 "Ā· Ratio SAD Threshold: %f\n",
SAD_RATIO);
2556 "Ā· Max. distance between desc: %f\n",
maxORB_dist);
2573 "Ā· Min/max disp limits: %.2f/%.2f px\n",
min_disp,
2593 "-------------------------------------------------------- \n");