30 using namespace gtsam;
54 static Symbol body_P_cam1_key(
'P', 1);
55 static Symbol body_P_cam2_key(
'P', 2);
56 static Symbol body_P_cam3_key(
'P', 3);
59 static Key poseExtrinsicKey1(body_P_cam1_key);
60 static Key poseExtrinsicKey2(body_P_cam2_key);
65 static Pose3 body_P_sensor1(Rot3::RzRyRx(-M_PI_2, 0.0, -M_PI_2),
68 static double missing_uR = std::numeric_limits<double>::quiet_NaN();
70 vector<StereoPoint2> stereo_projectToMultipleCameras(
const StereoCamera&
cam1,
74 vector<StereoPoint2> measurements_cam;
79 measurements_cam.push_back(cam1_uv1);
80 measurements_cam.push_back(cam2_uv1);
81 measurements_cam.push_back(cam3_uv1);
83 return measurements_cam;
153 EXPECT(!factor1->equals(*factor3));
158 EXPECT(!factor1->equals(*factor4));
182 values.
insert(body_P_cam1_key, Pose3::Identity());
183 values.
insert(body_P_cam2_key, Pose3::Identity());
186 factor1.
add(cam1_uv,
x1, body_P_cam1_key,
K2);
187 factor1.
add(cam2_uv,
x2, body_P_cam2_key,
K2);
189 double actualError = factor1.
error(values);
190 double expectedError = 0.0;
216 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI / 2, 0., 0.0),
218 Pose3 body_Pose_cam2 = Pose3(Rot3::Ypr(-
M_PI / 4, 0., 0.0),
220 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.
inverse());
221 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam2.
inverse());
226 values.
insert(body_P_cam1_key, body_Pose_cam1);
227 values.
insert(body_P_cam2_key, body_Pose_cam2);
230 factor1.
add(cam1_uv,
x1, body_P_cam1_key,
K2);
231 factor1.
add(cam2_uv,
x2, body_P_cam2_key,
K2);
233 double actualError = factor1.
error(values);
234 double expectedError = 0.0;
260 StereoPoint2 cam2_uv_right_missing(cam2_uv.
uL(),missing_uR,cam2_uv.
v());
263 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
265 Pose3 body_Pose_cam2 = Pose3(Rot3::Ypr(-
M_PI / 4, 0.1, 1.0),
267 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.inverse());
268 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam2.
inverse());
273 values.
insert(body_P_cam1_key, body_Pose_cam1);
274 values.
insert(body_P_cam2_key, body_Pose_cam2);
277 factor1.
add(cam1_uv,
x1, body_P_cam1_key,
K2);
278 factor1.
add(cam2_uv_right_missing,
x2, body_P_cam2_key,
K2);
280 double actualError = factor1.
error(values);
281 double expectedError = 0.0;
297 StereoPoint2 cam1_uv_right_missing(cam1_uv.
uL(),missing_uR,cam1_uv.
v());
298 factor2.
add(cam1_uv_right_missing,
x1, body_P_cam1_key,
K2);
299 factor2.
add(cam2_uv_right_missing,
x2, body_P_cam2_key,
K2);
325 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
327 Pose3 body_Pose_cam2 = Pose3(Rot3::Ypr(-
M_PI / 4, 0.1, 1.0),
329 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.
inverse());
330 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam2.
inverse());
334 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 10, 0., -
M_PI / 10),
337 values.
insert(body_P_cam1_key, body_Pose_cam1);
338 values.
insert(body_P_cam2_key, body_Pose_cam2);
341 factor1->add(cam1_uv,
x1, body_P_cam1_key,
K);
342 factor1->add(cam2_uv,
x2, body_P_cam2_key,
K);
344 double actualError1 = factor1->error(values);
347 vector<StereoPoint2> measurements;
348 measurements.push_back(cam1_uv);
349 measurements.push_back(cam2_uv);
351 vector<std::shared_ptr<Cal3_S2Stereo> > Ks;
356 poseKeys.push_back(
x1);
357 poseKeys.push_back(
x2);
360 extrinsicKeys.push_back(body_P_cam1_key);
361 extrinsicKeys.push_back(body_P_cam2_key);
363 factor2->add(measurements, poseKeys, extrinsicKeys, Ks);
365 double actualError2 = factor2->error(values);
383 Pose3 w_Pose_cam3 = w_Pose_cam1 * Pose3(
Rot3(),
Point3(0, -1, 0));
389 Point3 landmark3(3, 0, 3.0);
392 vector<StereoPoint2> measurements_l1 = stereo_projectToMultipleCameras(cam1,
393 cam2, cam3, landmark1);
394 vector<StereoPoint2> measurements_l2 = stereo_projectToMultipleCameras(cam1,
395 cam2, cam3, landmark2);
396 vector<StereoPoint2> measurements_l3 = stereo_projectToMultipleCameras(cam1,
397 cam2, cam3, landmark3);
400 poseKeys.push_back(
x1);
401 poseKeys.push_back(
x2);
402 poseKeys.push_back(
x3);
405 extrinsicKeys.push_back(body_P_cam1_key);
406 extrinsicKeys.push_back(body_P_cam2_key);
407 extrinsicKeys.push_back(body_P_cam3_key);
412 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
415 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
418 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
420 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
423 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
424 Pose3 body_Pose_cam2 = Pose3(Rot3::Ypr(-
M_PI / 4, 0.1, 1.0),
Point3(1, 1, 1));
425 Pose3 body_Pose_cam3 = Pose3::Identity();
426 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.
inverse());
427 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam2.
inverse());
428 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam3.
inverse());
431 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.1, 0.1, 0.1));
435 values.
insert(body_P_cam1_key, body_Pose_cam1);
436 values.
insert(body_P_cam2_key, body_Pose_cam2);
438 values.
insert(body_P_cam3_key, body_Pose_cam3 * noise_pose);
449 graph.
addPrior(body_P_cam1_key, body_Pose_cam1, noisePrior);
450 graph.
addPrior(body_P_cam2_key, body_Pose_cam2, noisePrior);
455 Rot3(0, -0.0314107591, 0.99950656, -0.99950656, -0.0313952598,
456 -0.000986635786, 0.0314107591, -0.999013364, -0.0313952598),
457 Point3(0.1, -0.1, 1.9)), values.
at<Pose3>(
x3) * values.
at<Pose3>(body_P_cam3_key)));
463 Point3 landmark1_smart = *smartFactor1->point();
464 Point3 landmark2_smart = *smartFactor2->point();
465 Point3 landmark3_smart = *smartFactor3->point();
468 double initialErrorSmart = graph.
error(values);
497 values2.
insert(
x3, w_Pose_cam3 * noise_pose);
498 values2.
insert(
L(1), landmark1_smart);
499 values2.
insert(
L(2), landmark2_smart);
500 values2.
insert(
L(3), landmark3_smart);
510 bool verboseCheirality =
true;
513 graph2.
push_back(ProjectionFactor(measurements_l1[0],
model,
x1,
L(1),
K2,
false, verboseCheirality));
514 graph2.
push_back(ProjectionFactor(measurements_l1[1],
model,
x2,
L(1),
K2,
false, verboseCheirality));
515 graph2.
push_back(ProjectionFactor(measurements_l1[2],
model,
x3,
L(1),
K2,
false, verboseCheirality));
517 graph2.
push_back(ProjectionFactor(measurements_l2[0],
model,
x1,
L(2),
K2,
false, verboseCheirality));
518 graph2.
push_back(ProjectionFactor(measurements_l2[1],
model,
x2,
L(2),
K2,
false, verboseCheirality));
519 graph2.
push_back(ProjectionFactor(measurements_l2[2],
model,
x3,
L(2),
K2,
false, verboseCheirality));
521 graph2.
push_back(ProjectionFactor(measurements_l3[0],
model,
x1,
L(3),
K2,
false, verboseCheirality));
522 graph2.
push_back(ProjectionFactor(measurements_l3[1],
model,
x2,
L(3),
K2,
false, verboseCheirality));
523 graph2.
push_back(ProjectionFactor(measurements_l3[2],
model,
x3,
L(3),
K2,
false, verboseCheirality));
530 Values result2 = optimizer2.optimize();
546 Pose3 w_Pose_cam3 = w_Pose_cam1 * Pose3(
Rot3(),
Point3(0, -1, 0));
552 Point3 landmark3(3, 0, 3.0);
555 vector<StereoPoint2> measurements_l1 = stereo_projectToMultipleCameras(cam1,
556 cam2, cam3, landmark1);
557 vector<StereoPoint2> measurements_l2 = stereo_projectToMultipleCameras(cam1,
558 cam2, cam3, landmark2);
559 vector<StereoPoint2> measurements_l3 = stereo_projectToMultipleCameras(cam1,
560 cam2, cam3, landmark3);
563 poseKeys.push_back(
x1);
564 poseKeys.push_back(
x2);
565 poseKeys.push_back(
x3);
567 Symbol body_P_cam_key(
'P', 0);
569 extrinsicKeys.push_back(body_P_cam_key);
570 extrinsicKeys.push_back(body_P_cam_key);
571 extrinsicKeys.push_back(body_P_cam_key);
576 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
579 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
582 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
584 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
587 Pose3 body_Pose_cam = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
588 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam.
inverse());
589 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam.
inverse());
590 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam.
inverse());
593 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.01, 0.01, 0.01));
597 values.
insert(body_P_cam_key, body_Pose_cam);
609 double initialErrorSmart = graph.
error(values);
625 Pose3 w_Pose_cam3 = w_Pose_cam1 * Pose3(
Rot3(),
Point3(0, -1, 0));
631 Point3 landmark3(3, 0, 3.0);
634 vector<StereoPoint2> measurements_l1 = stereo_projectToMultipleCameras(cam1,
635 cam2, cam3, landmark1);
636 vector<StereoPoint2> measurements_l2 = stereo_projectToMultipleCameras(cam1,
637 cam2, cam3, landmark2);
638 vector<StereoPoint2> measurements_l3 = stereo_projectToMultipleCameras(cam1,
639 cam2, cam3, landmark3);
641 double initialError_expected, initialError_actual;
644 poseKeys.push_back(
x1);
645 poseKeys.push_back(
x2);
646 poseKeys.push_back(
x3);
649 extrinsicKeys.push_back(body_P_cam1_key);
650 extrinsicKeys.push_back(body_P_cam2_key);
651 extrinsicKeys.push_back(body_P_cam3_key);
656 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
659 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
662 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
664 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
667 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
668 Pose3 body_Pose_cam2 = body_Pose_cam1;
669 Pose3 body_Pose_cam3 = body_Pose_cam1;
670 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.
inverse());
671 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam2.
inverse());
672 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam3.
inverse());
675 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.1, 0.1, 0.1));
679 values.
insert(body_P_cam1_key, body_Pose_cam1 * noise_pose);
680 values.
insert(body_P_cam2_key, body_Pose_cam2 * noise_pose);
682 values.
insert(body_P_cam3_key, body_Pose_cam3 * noise_pose);
693 initialError_expected = graph.
error(values);
698 poseKeys.push_back(
x1);
699 poseKeys.push_back(
x2);
700 poseKeys.push_back(
x3);
703 extrinsicKeys.push_back(body_P_cam1_key);
704 extrinsicKeys.push_back(body_P_cam1_key);
705 extrinsicKeys.push_back(body_P_cam1_key);
710 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
713 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
716 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
718 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
721 Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
722 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam1.
inverse());
723 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam1.
inverse());
724 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam1.
inverse());
727 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.1, 0.1, 0.1));
731 values.
insert(body_P_cam1_key, body_Pose_cam1 * noise_pose);
742 initialError_actual = graph.
error(values);
761 Pose3 w_Pose_cam3 = w_Pose_cam1 * Pose3(
Rot3(),
Point3(0, -1, 0));
767 Point3 landmark3(3, 0, 3.0);
770 vector<StereoPoint2> measurements_l1 = stereo_projectToMultipleCameras(cam1,
771 cam2, cam3, landmark1);
772 vector<StereoPoint2> measurements_l2 = stereo_projectToMultipleCameras(cam1,
773 cam2, cam3, landmark2);
774 vector<StereoPoint2> measurements_l3 = stereo_projectToMultipleCameras(cam1,
775 cam2, cam3, landmark3);
778 poseKeys.push_back(
x1);
779 poseKeys.push_back(
x2);
780 poseKeys.push_back(
x3);
782 Symbol body_P_cam_key(
'P', 0);
784 extrinsicKeys.push_back(body_P_cam_key);
785 extrinsicKeys.push_back(body_P_cam_key);
786 extrinsicKeys.push_back(body_P_cam_key);
791 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
794 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
797 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
800 Pose3 body_Pose_cam = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
801 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam.
inverse());
802 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam.
inverse());
803 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam.
inverse());
806 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
819 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.01, 0.01, 0.01));
823 values.
insert(body_P_cam_key, body_Pose_cam*noise_pose);
826 double initialErrorSmart = graph.
error(values);
883 Pose3 w_Pose_cam3 = w_Pose_cam1 * Pose3(
Rot3(),
Point3(0, -1, 0));
889 Point3 landmark3(3, 0, 3.0);
892 vector<StereoPoint2> measurements_l1 = stereo_projectToMultipleCameras(cam1,
893 cam2, cam3, landmark1);
894 vector<StereoPoint2> measurements_l2 = stereo_projectToMultipleCameras(cam1,
895 cam2, cam3, landmark2);
896 vector<StereoPoint2> measurements_l3 = stereo_projectToMultipleCameras(cam1,
897 cam2, cam3, landmark3);
900 poseKeys.push_back(
x1);
901 poseKeys.push_back(
x2);
902 poseKeys.push_back(
x3);
905 extrinsicKeys.push_back(body_P_cam1_key);
906 extrinsicKeys.push_back(body_P_cam1_key);
907 extrinsicKeys.push_back(body_P_cam3_key);
912 smartFactor1->add(measurements_l1, poseKeys, extrinsicKeys,
K2);
915 smartFactor2->add(measurements_l2, poseKeys, extrinsicKeys,
K2);
918 smartFactor3->add(measurements_l3, poseKeys, extrinsicKeys,
K2);
921 Pose3 body_Pose_cam = Pose3(Rot3::Ypr(-
M_PI, 1., 0.1),
Point3(0, 1, 0));
922 Pose3 w_Pose_body1 = w_Pose_cam1.
compose(body_Pose_cam.
inverse());
923 Pose3 w_Pose_body2 = w_Pose_cam2.
compose(body_Pose_cam.
inverse());
924 Pose3 w_Pose_body3 = w_Pose_cam3.
compose(body_Pose_cam.
inverse());
927 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
941 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.01, 0.01, 0.01));
945 values.
insert(body_P_cam1_key, body_Pose_cam*noise_pose);
946 values.
insert(body_P_cam3_key, body_Pose_cam*noise_pose);
949 double initialErrorSmart = graph.
error(values);
979 Pose3 cameraPose3 = cameraPose1 * Pose3(
Rot3(),
Point3(0,-1,0));
996 Point3 landmark3(5, 0, 3.0);
998 Point2Vector measurements_cam1, measurements_cam2, measurements_cam3;
1006 vector<StereoPoint2> measurements_cam1_stereo, measurements_cam2_stereo, measurements_cam3_stereo;
1007 for(
size_t k=0; k<measurements_cam1.size();k++)
1008 measurements_cam1_stereo.push_back(
StereoPoint2(measurements_cam1[k].
x() , missing_uR , measurements_cam1[k].
y()));
1010 for(
size_t k=0; k<measurements_cam2.size();k++)
1011 measurements_cam2_stereo.push_back(
StereoPoint2(measurements_cam2[k].
x() , missing_uR , measurements_cam2[k].
y()));
1013 for(
size_t k=0; k<measurements_cam3.size();k++)
1014 measurements_cam3_stereo.push_back(
StereoPoint2(measurements_cam3[k].
x() , missing_uR , measurements_cam3[k].
y()));
1017 poseKeys.push_back(
x1);
1018 poseKeys.push_back(
x2);
1019 poseKeys.push_back(
x3);
1021 Symbol body_P_cam_key(
'P', 0);
1023 extrinsicKeys.push_back(body_P_cam_key);
1024 extrinsicKeys.push_back(body_P_cam_key);
1025 extrinsicKeys.push_back(body_P_cam_key);
1035 smartFactor1.
add(measurements_cam1_stereo, poseKeys, extrinsicKeys, Kmono);
1038 smartFactor2.
add(measurements_cam2_stereo, poseKeys, extrinsicKeys, Kmono);
1041 smartFactor3.
add(measurements_cam3_stereo, poseKeys, extrinsicKeys, Kmono);
1044 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1060 gtValues.
insert(body_P_cam_key, sensor_to_body);
1061 double actualError = graph.
error(gtValues);
1062 double expectedError = 0.0;
1067 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
Point3(0.01, 0.01, 0.01));
1071 values.
insert(body_P_cam_key, sensor_to_body*noise_pose);
1074 double initialErrorSmart = graph.
error(values);
1102 views.push_back(
x1);
1103 views.push_back(
x2);
1104 views.push_back(
x3);
1106 Symbol body_P_cam_key(
'P', 0);
1108 extrinsicKeys.push_back(body_P_cam_key);
1109 extrinsicKeys.push_back(body_P_cam_key);
1110 extrinsicKeys.push_back(body_P_cam_key);
1115 Point3 landmark3(3, 0, 3.0);
1118 vector<StereoPoint2> measurements_cam1 = stereo_projectToMultipleCameras(cam1,
1119 cam2, cam3, landmark1);
1120 vector<StereoPoint2> measurements_cam2 = stereo_projectToMultipleCameras(cam1,
1121 cam2, cam3, landmark2);
1122 vector<StereoPoint2> measurements_cam3 = stereo_projectToMultipleCameras(cam1,
1123 cam2, cam3, landmark3);
1130 smartFactor1->add(measurements_cam1, views, extrinsicKeys,
K);
1133 smartFactor2->add(measurements_cam2, views, extrinsicKeys,
K);
1136 smartFactor3->add(measurements_cam3, views, extrinsicKeys,
K);
1139 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1146 graph.
addPrior(body_P_cam_key, Pose3::Identity(), noisePrior);
1149 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
1154 values.
insert(
x3, pose3 * noise_pose);
1155 values.
insert(body_P_cam_key, Pose3::Identity());
1169 views.push_back(
x1);
1170 views.push_back(
x2);
1171 views.push_back(
x3);
1173 Symbol body_P_cam_key(
'P', 0);
1175 extrinsicKeys.push_back(body_P_cam_key);
1176 extrinsicKeys.push_back(body_P_cam_key);
1177 extrinsicKeys.push_back(body_P_cam_key);
1192 Point3 landmark3(3, 0, 3.0);
1193 Point3 landmark4(5, -0.5, 1);
1196 vector<StereoPoint2> measurements_cam1 = stereo_projectToMultipleCameras(cam1,
1197 cam2, cam3, landmark1);
1198 vector<StereoPoint2> measurements_cam2 = stereo_projectToMultipleCameras(cam1,
1199 cam2, cam3, landmark2);
1200 vector<StereoPoint2> measurements_cam3 = stereo_projectToMultipleCameras(cam1,
1201 cam2, cam3, landmark3);
1202 vector<StereoPoint2> measurements_cam4 = stereo_projectToMultipleCameras(cam1,
1203 cam2, cam3, landmark4);
1205 measurements_cam4.at(0) = measurements_cam4.at(0) +
StereoPoint2(10, 10, 1);
1212 smartFactor1->add(measurements_cam1, views, extrinsicKeys,
K);
1215 smartFactor2->add(measurements_cam2, views, extrinsicKeys,
K);
1218 smartFactor3->add(measurements_cam3, views, extrinsicKeys,
K);
1221 smartFactor4->add(measurements_cam4, views, extrinsicKeys,
K);
1225 smartFactor4b->add(measurements_cam4, views, extrinsicKeys,
K);
1227 const SharedDiagonal noisePrior = noiseModel::Isotropic::Sigma(6, 0.10);
1238 Pose3 noise_pose = Pose3(Rot3::Ypr(-
M_PI / 100, 0., -
M_PI / 100),
1244 values.
insert(body_P_cam_key, Pose3::Identity());
1256 EXPECT(smartFactor1->point());
1257 EXPECT(smartFactor2->point());
1258 EXPECT(smartFactor3->point());
1259 EXPECT(smartFactor4->point().outlier());
1260 EXPECT(smartFactor4b->point());
static PinholeCamera< Cal3_S2 > cam1(pose3, cal1)
virtual const Values & optimize()
TEST(SmartStereoProjectionFactorPP, params)
Camera cam3(interp_pose3, sharedK)
bool getVerboseCheirality() const
static int runAllTests(TestResult &result)
noiseModel::Diagonal::shared_ptr model
const ValueType at(Key j) const
void setRetriangulationThreshold(double retriangulationTh)
static StereoCamera cam2(pose3, cal4ptr)
#define DOUBLES_EQUAL(expected, actual, threshold)
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
void setEnableEPI(bool enableEPI)
CameraSet< Camera > Cameras
double error(const Values &values) const override
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
TriangulationParameters triangulation
double dynamicOutlierRejectionThreshold
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
static Point2 measurement2(200.0, 220.0)
NonlinearFactorGraph graph
A set of cameras, all with their own calibration.
Point2 landmark1(5.0, 1.5)
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
DegeneracyMode getDegeneracyMode() const
Pose3 inverse() const
inverse transformation with derivatives
static const SmartProjectionParams params
static Point3 landmark(0, 0, 5)
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
void setRankTolerance(double rankTol)
Implements a prior on the translation component of a pose.
static const Cal3Bundler K2(625, 1e-3, 1e-3)
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Point2 landmark2(7.0, 1.5)
double getRetriangulationThreshold() const
double landmarkDistanceThreshold
std::shared_ptr< Cal3_S2 > shared_ptr
The most common 5DOF 3D->2D calibration, stereo version.
bool enableEPI
if set to true, will refine triangulation using LM
double rankTolerance
(the rank is the number of singular values of the triangulation matrix which are larger than rankTole...
#define EXPECT(condition)
static Pose3 pose3(rt3, pt3)
static Point2 measurement1(323.0, 240.0)
void projectToMultipleCameras(const CAMERA &cam1, const CAMERA &cam2, const CAMERA &cam3, Point3 landmark, typename CAMERA::MeasurementVector &measurements_cam)
void setLandmarkDistanceThreshold(double landmarkDistanceThreshold)
TEST_UNSAFE(SmartStereoProjectionFactorPP, noiseless_error_identityExtrinsics)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Derived from ProjectionFactor, but estimates body-camera transform in addition to body pose and 3D la...
The most common 5DOF 3D->2D calibration.
bool getThrowCheirality() const
StereoPoint2 project(const Point3 &point) const
Project 3D point to StereoPoint2 (uL,uR,v)
std::shared_ptr< This > shared_ptr
shared_ptr to this class
double error(const Values &values) const
Class compose(const Class &g) const
Reprojection of a LANDMARK to a 2D point.
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
std::shared_ptr< Cal3_S2Stereo > shared_ptr
static const Pose3 pose1(Rot3(), Point3(0, 1, 0.5))
A non-linear factor for stereo measurements.
NonlinearFactorGraph graph2()
noiseModel::Diagonal::shared_ptr SharedDiagonal
static Key poseKey1(X(1))
TriangulationResult triangulateSafe(const Cameras &cameras) const
triangulateSafe
void add(const StereoPoint2 &measured, const Key &world_P_body_key, const Key &body_P_cam_key, const std::shared_ptr< Cal3_S2Stereo > &K)
void setDegeneracyMode(DegeneracyMode degMode)
Base::Cameras cameras(const Values &values) const override
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
void insert(Key j, const Value &val)
void setLinearizationMode(LinearizationMode linMode)
void tictoc_finishedIteration_()
LinearizationMode getLinearizationMode() const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
void setDynamicOutlierRejectionThreshold(double dynOutRejectionThreshold)
std::uint64_t Key
Integer nonlinear key type.
noiseModel::Base::shared_ptr SharedNoiseModel
TriangulationParameters getTriangulationParameters() const
Smart stereo factor on poses and extrinsic calibration.