Merged in feature/stereocamera_backproject_addJacobian (pull request #153)
Add optional jacobians to StereoCamera backprojectionrelease/4.3a0
commit
68d9905359
|
|
@ -91,8 +91,42 @@ namespace gtsam {
|
|||
double Z = K_->baseline() * K_->fx() / (measured[0] - measured[1]);
|
||||
double X = Z * (measured[0] - K_->px()) / K_->fx();
|
||||
double Y = Z * (measured[2] - K_->py()) / K_->fy();
|
||||
Point3 world_point = leftCamPose_.transform_from(Point3(X, Y, Z));
|
||||
return world_point;
|
||||
Point3 point = leftCamPose_.transform_from(Point3(X, Y, Z));
|
||||
return point;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
Point3 StereoCamera::backproject2(const StereoPoint2& z, OptionalJacobian<3, 6> H1,
|
||||
OptionalJacobian<3, 3> H2) const {
|
||||
const Cal3_S2Stereo& K = *K_;
|
||||
const double fx = K.fx(), fy = K.fy(), cx = K.px(), cy = K.py(), b = K.baseline();
|
||||
|
||||
double uL = z.uL(), uR = z.uR(), v = z.v();
|
||||
double disparity = uL - uR;
|
||||
|
||||
double local_z = b * fx / disparity;
|
||||
const Point3 local(local_z * (uL - cx)/ fx, local_z * (v - cy) / fy, local_z);
|
||||
|
||||
if(H1 || H2) {
|
||||
double z_partial_uR = local_z/disparity;
|
||||
double x_partial_uR = local.x()/disparity;
|
||||
double y_partial_uR = local.y()/disparity;
|
||||
Matrix3 D_local_z;
|
||||
D_local_z << -x_partial_uR + local.z()/fx, x_partial_uR, 0,
|
||||
-y_partial_uR, y_partial_uR, local.z() / fy,
|
||||
-z_partial_uR, z_partial_uR, 0;
|
||||
|
||||
Matrix3 D_point_local;
|
||||
const Point3 point = leftCamPose_.transform_from(local, H1, D_point_local);
|
||||
|
||||
if(H2) {
|
||||
*H2 = D_point_local * D_local_z;
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
return leftCamPose_.transform_from(local);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,14 @@ public:
|
|||
/// back-project a measurement
|
||||
Point3 backproject(const StereoPoint2& z) const;
|
||||
|
||||
/** Back-project the 2D point and compute optional derivatives
|
||||
* @param H1 derivative with respect to pose
|
||||
* @param H2 derivative with respect to point
|
||||
*/
|
||||
Point3 backproject2(const StereoPoint2& z,
|
||||
OptionalJacobian<3, 6> H1 = boost::none,
|
||||
OptionalJacobian<3, 3> H2 = boost::none) const;
|
||||
|
||||
/// @}
|
||||
/// @name Deprecated
|
||||
/// @{
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ TEST( StereoCamera, Dproject)
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( StereoCamera, backproject)
|
||||
TEST( StereoCamera, backproject_case1)
|
||||
{
|
||||
Cal3_S2Stereo::shared_ptr K2(new Cal3_S2Stereo(1500, 1500, 0, 320, 240, 0.5));
|
||||
StereoCamera stereoCam2(Pose3(), K2);
|
||||
|
|
@ -117,7 +117,7 @@ TEST( StereoCamera, backproject)
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( StereoCamera, backproject2)
|
||||
TEST( StereoCamera, backproject_case2)
|
||||
{
|
||||
Rot3 R(0.589511291, -0.804859792, 0.0683931805,
|
||||
-0.804435942, -0.592650676, -0.0405925523,
|
||||
|
|
@ -132,6 +132,53 @@ TEST( StereoCamera, backproject2)
|
|||
CHECK(assert_equal(z, actual, 1e-3));
|
||||
}
|
||||
|
||||
static Point3 backproject3(const Pose3& pose, const StereoPoint2& point, const Cal3_S2Stereo& K) {
|
||||
return StereoCamera(pose, boost::make_shared<Cal3_S2Stereo>(K)).backproject(point);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( StereoCamera, backproject2_case1)
|
||||
{
|
||||
Cal3_S2Stereo::shared_ptr K2(new Cal3_S2Stereo(1500, 1500, 0, 320, 240, 0.5));
|
||||
StereoCamera stereoCam2(Pose3(), K2);
|
||||
|
||||
Point3 expected_point(1.2, 2.3, 4.5);
|
||||
StereoPoint2 stereo_point = stereoCam2.project(expected_point);
|
||||
|
||||
Matrix actual_jacobian_1, actual_jacobian_2;
|
||||
Point3 actual_point = stereoCam2.backproject2(stereo_point, actual_jacobian_1, actual_jacobian_2);
|
||||
CHECK(assert_equal(expected_point, actual_point, 1e-8));
|
||||
|
||||
Matrix expected_jacobian_to_pose = numericalDerivative31(backproject3, Pose3(), stereo_point, *K2);
|
||||
CHECK(assert_equal(expected_jacobian_to_pose, actual_jacobian_1, 1e-6));
|
||||
|
||||
Matrix expected_jacobian_to_point = numericalDerivative32(backproject3, Pose3(), stereo_point, *K2);
|
||||
CHECK(assert_equal(expected_jacobian_to_point, actual_jacobian_2, 1e-6));
|
||||
}
|
||||
|
||||
TEST( StereoCamera, backproject2_case2)
|
||||
{
|
||||
Rot3 R(0.589511291, -0.804859792, 0.0683931805,
|
||||
-0.804435942, -0.592650676, -0.0405925523,
|
||||
0.0732045588, -0.0310882277, -0.996832359);
|
||||
Point3 t(53.5239823, 23.7866016, -4.42379876);
|
||||
Cal3_S2Stereo::shared_ptr K(new Cal3_S2Stereo(1733.75, 1733.75, 0, 689.645, 508.835, 0.0699612));
|
||||
StereoCamera camera(Pose3(R,t), K);
|
||||
StereoPoint2 z(184.812, 129.068, 714.768);
|
||||
|
||||
Matrix actual_jacobian_1, actual_jacobian_2;
|
||||
Point3 l = camera.backproject2(z, actual_jacobian_1, actual_jacobian_2);
|
||||
|
||||
StereoPoint2 actual = camera.project(l);
|
||||
CHECK(assert_equal(z, actual, 1e-3));
|
||||
|
||||
Matrix expected_jacobian_to_pose = numericalDerivative31(backproject3, Pose3(R,t), z, *K);
|
||||
CHECK(assert_equal(expected_jacobian_to_pose, actual_jacobian_1, 1e-6));
|
||||
|
||||
Matrix expected_jacobian_to_point = numericalDerivative32(backproject3, Pose3(R,t), z, *K);
|
||||
CHECK(assert_equal(expected_jacobian_to_point, actual_jacobian_2, 1e-6));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
|
||||
/* ************************************************************************* */
|
||||
|
|
|
|||
Loading…
Reference in New Issue