// // Created by root on 4/13/21. // #ifndef SVO_VisionFactorLandMark_H #define SVO_VisionFactorLandMark_H #pragma once #include #include #include #include #include #include #include namespace vio { class VisionFactorLandMark: public gtsam::NoiseModelFactor3 { private: // measurement information gtsam::Point3 feature_new; /// shared_ptr; /** * Constructor * @param feature Unit-bearing vector of the feature. * @param model is the standard deviation * @param pointKey is the index of the landmark * @param poseKey is the index of the camera pose * @param landmark 3D position of the landmark * @param body_P_sensor is the transform from body to sensor frame (default identity) * @param level Image pyramid level where feature was extracted. */ VisionFactorLandMark(const gtsam::Point3& feature_new,const gtsam::Point3& feature_ref, int level, const gtsam::SharedNoiseModel& H, gtsam::Key poseKey_ref, gtsam::Key poseKey_new,gtsam::Key landmarkKey ) : gtsam::NoiseModelFactor3(H, poseKey_ref,poseKey_new,landmarkKey), feature_new(feature_new), feature_ref(feature_ref),level(level){} virtual ~VisionFactorLandMark(){} /// error function /// @param p_new the Estimated pose in Pose3 /// @param P_ref the Estimated point of landmark /// @param l the Estimated point of landmark /// @param H the optional Jacobian matrix, which use boost optional and has default null pointer gtsam::Vector evaluateError(const gtsam::Pose3& p_ref,const gtsam::Pose3& p_new, const gtsam::Point3& l, boost::optional H1 = boost::none,boost::optional H2 = boost::none, boost::optional H3 = boost::none) const { // note that use boost optional like a pointer // only calculate jacobian matrix when non-null pointer exists gtsam::Matrix26 J,J1; gtsam::Matrix23 J2,J3; gtsam::Point3 point(p_ref*l); svo::Frame::jacobian_xyz2uv(point, J); svo::Frame::jacobian_l2uv(point,J2); gtsam::Point3 point2(p_new*l); svo::Frame::jacobian_xyz2uv(point2, J1); svo::Frame::jacobian_l2uv(point2,J3); Vector2d e1=vk::project2d(feature_ref) - vk::project2d(point)*1.0 / (1<( gtsam::NonlinearFactor::shared_ptr(new VisionFactorLandMark(*this))); } }; } // namespace gtsamexamples #endif //SVO_SVOVISIONFACTOR_H