all tests are passing!
parent
0d1c3f16ef
commit
a480b2dcfc
|
@ -108,129 +108,187 @@ TEST( ProjectionFactorRollingShutter, EqualsWithTransform ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
//TEST( ProjectionFactorRollingShutter, Error ) {
|
TEST( ProjectionFactorRollingShutter, Error ) {
|
||||||
// // Create the factor with a measurement that is 3 pixels off in x
|
{
|
||||||
// Key poseKey(X(1));
|
// Create the factor with a measurement that is 3 pixels off in x
|
||||||
// Key transformKey(T(1));
|
// Camera pose corresponds to the first camera
|
||||||
// Key pointKey(L(1));
|
double t = 0.0;
|
||||||
// Point2 measurement(323.0, 240.0);
|
ProjectionFactorRollingShutter factor(measurement, t, model, poseKey1, poseKey2, pointKey, K);
|
||||||
// ProjectionFactorRollingShutter factor(measurement, model, poseKey, transformKey, pointKey, K);
|
|
||||||
//
|
// Set the linearization point
|
||||||
// // Set the linearization point
|
Pose3 pose1(Rot3(), Point3(0,0,-6));
|
||||||
// Pose3 pose(Rot3(), Point3(0,0,-6));
|
Pose3 pose2(Rot3(), Point3(0,0,-4));
|
||||||
// Point3 point(0.0, 0.0, 0.0);
|
Point3 point(0.0, 0.0, 0.0);
|
||||||
//
|
|
||||||
// // Use the factor to calculate the error
|
// Use the factor to calculate the error
|
||||||
// Vector actualError(factor.evaluateError(pose, Pose3(), point));
|
Vector actualError(factor.evaluateError(pose1, pose2, point));
|
||||||
//
|
|
||||||
// // The expected error is (-3.0, 0.0) pixels / UnitCovariance
|
// The expected error is (-3.0, 0.0) pixels / UnitCovariance
|
||||||
// Vector expectedError = Vector2(-3.0, 0.0);
|
Vector expectedError = Vector2(-3.0, 0.0);
|
||||||
//
|
|
||||||
// // Verify we get the expected error
|
// Verify we get the expected error
|
||||||
// CHECK(assert_equal(expectedError, actualError, 1e-9));
|
CHECK(assert_equal(expectedError, actualError, 1e-9));
|
||||||
//}
|
}
|
||||||
//
|
{
|
||||||
///* ************************************************************************* */
|
// Create the factor with a measurement that is 3 pixels off in x
|
||||||
//TEST( ProjectionFactorRollingShutter, ErrorWithTransform ) {
|
// Camera pose is actually interpolated now
|
||||||
// // Create the factor with a measurement that is 3 pixels off in x
|
double t = 0.5;
|
||||||
// Key poseKey(X(1));
|
ProjectionFactorRollingShutter factor(measurement, t, model, poseKey1, poseKey2, pointKey, K);
|
||||||
// Key transformKey(T(1));
|
|
||||||
// Key pointKey(L(1));
|
// Set the linearization point
|
||||||
// Point2 measurement(323.0, 240.0);
|
Pose3 pose1(Rot3(), Point3(0,0,-8));
|
||||||
// Pose3 transform(Rot3::RzRyRx(-M_PI_2, 0.0, -M_PI_2), Point3(0.25, -0.10, 1.0));
|
Pose3 pose2(Rot3(), Point3(0,0,-4));
|
||||||
// ProjectionFactorRollingShutter factor(measurement, model, poseKey,transformKey, pointKey, K);
|
Point3 point(0.0, 0.0, 0.0);
|
||||||
//
|
|
||||||
// // Set the linearization point. The vehicle pose has been selected to put the camera at (-6, 0, 0)
|
// Use the factor to calculate the error
|
||||||
// Pose3 pose(Rot3(), Point3(-6.25, 0.10 , -1.0));
|
Vector actualError(factor.evaluateError(pose1, pose2, point));
|
||||||
// Point3 point(0.0, 0.0, 0.0);
|
|
||||||
//
|
// The expected error is (-3.0, 0.0) pixels / UnitCovariance
|
||||||
// // Use the factor to calculate the error
|
Vector expectedError = Vector2(-3.0, 0.0);
|
||||||
// Vector actualError(factor.evaluateError(pose, transform, point));
|
|
||||||
//
|
// Verify we get the expected error
|
||||||
// // The expected error is (-3.0, 0.0) pixels / UnitCovariance
|
CHECK(assert_equal(expectedError, actualError, 1e-9));
|
||||||
// Vector expectedError = Vector2(-3.0, 0.0);
|
}
|
||||||
//
|
{
|
||||||
// // Verify we get the expected error
|
// Create measurement by projecting 3D landmark
|
||||||
// CHECK(assert_equal(expectedError, actualError, 1e-9));
|
double t = 0.3;
|
||||||
//}
|
Pose3 pose1(Rot3::RzRyRx(0.1, 0.0, 0.1), Point3(0,0,0));
|
||||||
//
|
Pose3 pose2(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0,1));
|
||||||
///* ************************************************************************* */
|
Pose3 poseInterp = interpolate<Pose3>(pose1, pose2, t);
|
||||||
//TEST( ProjectionFactorRollingShutter, Jacobian ) {
|
PinholeCamera<Cal3_S2> camera(poseInterp, *K);
|
||||||
// // Create the factor with a measurement that is 3 pixels off in x
|
Point3 point(0.0, 0.0, 5.0); // 5 meters in front of the camera
|
||||||
// Key poseKey(X(1));
|
Point2 measured = camera.project(point);
|
||||||
// Key transformKey(T(1));
|
|
||||||
// Key pointKey(L(1));
|
// create factor
|
||||||
// Point2 measurement(323.0, 240.0);
|
ProjectionFactorRollingShutter factor(measured, t, model, poseKey1, poseKey2, pointKey, K);
|
||||||
// ProjectionFactorRollingShutter factor(measurement, model, poseKey, transformKey, pointKey, K);
|
|
||||||
//
|
// Use the factor to calculate the error
|
||||||
// // Set the linearization point
|
Vector actualError(factor.evaluateError(pose1, pose2, point));
|
||||||
// Pose3 pose(Rot3(), Point3(0,0,-6));
|
|
||||||
// Point3 point(0.0, 0.0, 0.0);
|
// The expected error is zero
|
||||||
//
|
Vector expectedError = Vector2(0.0, 0.0);
|
||||||
// // Use the factor to calculate the Jacobians
|
|
||||||
// Matrix H1Actual, H2Actual, H3Actual;
|
// Verify we get the expected error
|
||||||
// factor.evaluateError(pose, Pose3(), point, H1Actual, H2Actual, H3Actual);
|
CHECK(assert_equal(expectedError, actualError, 1e-9));
|
||||||
//
|
}
|
||||||
// // The expected Jacobians
|
}
|
||||||
// Matrix H1Expected = (Matrix(2, 6) << 0., -554.256, 0., -92.376, 0., 0., 554.256, 0., 0., 0., -92.376, 0.).finished();
|
|
||||||
// Matrix H3Expected = (Matrix(2, 3) << 92.376, 0., 0., 0., 92.376, 0.).finished();
|
/* ************************************************************************* */
|
||||||
//
|
TEST( ProjectionFactorRollingShutter, ErrorWithTransform ) {
|
||||||
// // Verify the Jacobians are correct
|
// Create measurement by projecting 3D landmark
|
||||||
// CHECK(assert_equal(H1Expected, H1Actual, 1e-3));
|
double t = 0.3;
|
||||||
// CHECK(assert_equal(H3Expected, H3Actual, 1e-3));
|
Pose3 pose1(Rot3::RzRyRx(0.1, 0.0, 0.1), Point3(0,0,0));
|
||||||
//
|
Pose3 pose2(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0,1));
|
||||||
// // Verify H2 with numerical derivative
|
Pose3 poseInterp = interpolate<Pose3>(pose1, pose2, t);
|
||||||
// Matrix H2Expected = numericalDerivative32<Vector, Pose3, Pose3, Point3>(
|
Pose3 body_P_sensor3(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0.2,0.1));
|
||||||
// std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
PinholeCamera<Cal3_S2> camera(poseInterp*body_P_sensor3, *K);
|
||||||
// std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
Point3 point(0.0, 0.0, 5.0); // 5 meters in front of the camera
|
||||||
// std::placeholders::_1, std::placeholders::_2,
|
Point2 measured = camera.project(point);
|
||||||
// std::placeholders::_3, boost::none, boost::none,
|
|
||||||
// boost::none)),
|
// create factor
|
||||||
// pose, Pose3(), point);
|
ProjectionFactorRollingShutter factor(measured, t, model, poseKey1, poseKey2, pointKey, K, body_P_sensor3);
|
||||||
//
|
|
||||||
// CHECK(assert_equal(H2Expected, H2Actual, 1e-5));
|
// Use the factor to calculate the error
|
||||||
//}
|
Vector actualError(factor.evaluateError(pose1, pose2, point));
|
||||||
//
|
|
||||||
///* ************************************************************************* */
|
// The expected error is zero
|
||||||
//TEST( ProjectionFactorRollingShutter, JacobianWithTransform ) {
|
Vector expectedError = Vector2(0.0, 0.0);
|
||||||
// // Create the factor with a measurement that is 3 pixels off in x
|
|
||||||
// Key poseKey(X(1));
|
// Verify we get the expected error
|
||||||
// Key transformKey(T(1));
|
CHECK(assert_equal(expectedError, actualError, 1e-9));
|
||||||
// Key pointKey(L(1));
|
}
|
||||||
// Point2 measurement(323.0, 240.0);
|
|
||||||
// Pose3 body_P_sensor(Rot3::RzRyRx(-M_PI_2, 0.0, -M_PI_2), Point3(0.25, -0.10, 1.0));
|
/* ************************************************************************* */
|
||||||
// ProjectionFactorRollingShutter factor(measurement, model, poseKey, transformKey, pointKey, K);
|
TEST( ProjectionFactorRollingShutter, Jacobian ) {
|
||||||
//
|
// Create measurement by projecting 3D landmark
|
||||||
// // Set the linearization point. The vehicle pose has been selected to put the camera at (-6, 0, 0)
|
double t = 0.3;
|
||||||
// Pose3 pose(Rot3(), Point3(-6.25, 0.10 , -1.0));
|
Pose3 pose1(Rot3::RzRyRx(0.1, 0.0, 0.1), Point3(0,0,0));
|
||||||
// Point3 point(0.0, 0.0, 0.0);
|
Pose3 pose2(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0,1));
|
||||||
//
|
Pose3 poseInterp = interpolate<Pose3>(pose1, pose2, t);
|
||||||
// // Use the factor to calculate the Jacobians
|
PinholeCamera<Cal3_S2> camera(poseInterp, *K);
|
||||||
// Matrix H1Actual, H2Actual, H3Actual;
|
Point3 point(0.0, 0.0, 5.0); // 5 meters in front of the camera
|
||||||
// factor.evaluateError(pose, body_P_sensor, point, H1Actual, H2Actual, H3Actual);
|
Point2 measured = camera.project(point);
|
||||||
//
|
|
||||||
// // The expected Jacobians
|
// create factor
|
||||||
// Matrix H1Expected = (Matrix(2, 6) << -92.376, 0., 577.350, 0., 92.376, 0., -9.2376, -577.350, 0., 0., 0., 92.376).finished();
|
ProjectionFactorRollingShutter factor(measured, t, model, poseKey1, poseKey2, pointKey, K);
|
||||||
// Matrix H3Expected = (Matrix(2, 3) << 0., -92.376, 0., 0., 0., -92.376).finished();
|
|
||||||
//
|
// Use the factor to calculate the Jacobians
|
||||||
// // Verify the Jacobians are correct
|
Matrix H1Actual, H2Actual, H3Actual;
|
||||||
// CHECK(assert_equal(H1Expected, H1Actual, 1e-3));
|
factor.evaluateError(pose1, pose2, point, H1Actual, H2Actual, H3Actual);
|
||||||
// CHECK(assert_equal(H3Expected, H3Actual, 1e-3));
|
|
||||||
//
|
// Expected Jacobians via numerical derivatives
|
||||||
// // Verify H2 with numerical derivative
|
Matrix H1Expected = numericalDerivative31<Vector, Pose3, Pose3, Point3>(
|
||||||
// Matrix H2Expected = numericalDerivative32<Vector, Pose3, Pose3, Point3>(
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
// std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
// std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
// std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
// std::placeholders::_3, boost::none, boost::none,
|
pose1, pose2, point);
|
||||||
// boost::none)),
|
|
||||||
// pose, body_P_sensor, point);
|
Matrix H2Expected = numericalDerivative32<Vector, Pose3, Pose3, Point3>(
|
||||||
//
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
// CHECK(assert_equal(H2Expected, H2Actual, 1e-5));
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
//
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
//
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
//}
|
pose1, pose2, point);
|
||||||
|
|
||||||
|
Matrix H3Expected = numericalDerivative33<Vector, Pose3, Pose3, Point3>(
|
||||||
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
|
pose1, pose2, point);
|
||||||
|
|
||||||
|
CHECK(assert_equal(H1Expected, H1Actual, 1e-5));
|
||||||
|
CHECK(assert_equal(H2Expected, H2Actual, 1e-5));
|
||||||
|
CHECK(assert_equal(H3Expected, H3Actual, 1e-5));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST( ProjectionFactorRollingShutter, JacobianWithTransform ) {
|
||||||
|
// Create measurement by projecting 3D landmark
|
||||||
|
double t = 0.6;
|
||||||
|
Pose3 pose1(Rot3::RzRyRx(0.1, 0.0, 0.1), Point3(0,0,0));
|
||||||
|
Pose3 pose2(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0,1));
|
||||||
|
Pose3 poseInterp = interpolate<Pose3>(pose1, pose2, t);
|
||||||
|
Pose3 body_P_sensor3(Rot3::RzRyRx(-0.1, -0.1, 0.0), Point3(0,0.2,0.1));
|
||||||
|
PinholeCamera<Cal3_S2> camera(poseInterp*body_P_sensor3, *K);
|
||||||
|
Point3 point(0.0, 0.0, 5.0); // 5 meters in front of the camera
|
||||||
|
Point2 measured = camera.project(point);
|
||||||
|
|
||||||
|
// create factor
|
||||||
|
ProjectionFactorRollingShutter factor(measured, t, model, poseKey1, poseKey2, pointKey, K, body_P_sensor3);
|
||||||
|
|
||||||
|
// Use the factor to calculate the Jacobians
|
||||||
|
Matrix H1Actual, H2Actual, H3Actual;
|
||||||
|
factor.evaluateError(pose1, pose2, point, H1Actual, H2Actual, H3Actual);
|
||||||
|
|
||||||
|
// Expected Jacobians via numerical derivatives
|
||||||
|
Matrix H1Expected = numericalDerivative31<Vector, Pose3, Pose3, Point3>(
|
||||||
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
|
pose1, pose2, point);
|
||||||
|
|
||||||
|
Matrix H2Expected = numericalDerivative32<Vector, Pose3, Pose3, Point3>(
|
||||||
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
|
pose1, pose2, point);
|
||||||
|
|
||||||
|
Matrix H3Expected = numericalDerivative33<Vector, Pose3, Pose3, Point3>(
|
||||||
|
std::function<Vector(const Pose3&, const Pose3&, const Point3&)>(
|
||||||
|
std::bind(&ProjectionFactorRollingShutter::evaluateError, &factor,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, boost::none, boost::none, boost::none)),
|
||||||
|
pose1, pose2, point);
|
||||||
|
|
||||||
|
CHECK(assert_equal(H1Expected, H1Actual, 1e-5));
|
||||||
|
CHECK(assert_equal(H2Expected, H2Actual, 1e-5));
|
||||||
|
CHECK(assert_equal(H3Expected, H3Actual, 1e-5));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
||||||
|
|
Loading…
Reference in New Issue