diff --git a/cpp/SimpleCamera.cpp b/cpp/SimpleCamera.cpp index a8243d5b3..751d25390 100644 --- a/cpp/SimpleCamera.cpp +++ b/cpp/SimpleCamera.cpp @@ -8,6 +8,8 @@ #include "SimpleCamera.h" #include "CalibratedCamera.h" +using namespace std; + namespace gtsam { /* ************************************************************************* */ @@ -24,10 +26,16 @@ namespace gtsam { SimpleCamera::~SimpleCamera() { } - Point2 SimpleCamera::project(const Point3 & P) const { - Point2 intrinsic = calibrated_.project(P); + pair SimpleCamera::projectSafe(const Point3& P) const { + Point3 cameraPoint = transform_to(calibrated_.pose(), P); + Point2 intrinsic = project_to_camera(cameraPoint); Point2 projection = uncalibrate(K_, intrinsic); - return projection; + return pair(projection, cameraPoint.z() > 0); + } + + Point2 SimpleCamera::project(const Point3 & P) const { + pair projected = projectSafe(P); + return projected.first; } SimpleCamera SimpleCamera::level(const Cal3_S2& K, const Pose2& pose2, double height) { @@ -38,6 +46,10 @@ namespace gtsam { // measurement functions and derivatives /* ************************************************************************* */ + pair projectSafe(const SimpleCamera& camera, const Point3& point) { + return camera.projectSafe(point); + } + Point2 project(const SimpleCamera& camera, const Point3& point) { return camera.project(point); } diff --git a/cpp/SimpleCamera.h b/cpp/SimpleCamera.h index cc9755b22..5bcf55741 100644 --- a/cpp/SimpleCamera.h +++ b/cpp/SimpleCamera.h @@ -37,6 +37,15 @@ namespace gtsam { return K_; } + + /** + * project a 3d point to the camera and also check the depth + */ + std::pair projectSafe(const Point3& P) const; + + /** + * project a 3d point to the camera + */ Point2 project(const Point3& P) const; /** @@ -59,6 +68,12 @@ namespace gtsam { // measurement functions and derivatives /* ************************************************************************* */ + /** + * This function receives the camera pose and the landmark location and + returns the location the point is supposed to appear in the image as well as the sign of the depth + */ + std::pair projectSafe(const SimpleCamera& camera, const Point3& point); + /** * This function receives the camera pose and the landmark location and returns the location the point is supposed to appear in the image