// // Created by root on 4/13/21. // #ifndef SVO_SVOVISIONFACTOR_H #define SVO_SVOVISIONFACTOR_H #pragma once #include #include #include #include #include #include #include namespace svo { class VisionFactor: public gtsam::NoiseModelFactor2 { private: // measurement information gtsam::Point3 feature; /// 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. */ VisionFactor(const gtsam::Point3& feature,const int level, const gtsam::SharedNoiseModel& H, gtsam::Key poseKey,gtsam::Key landKey ) : gtsam::NoiseModelFactor2(H, poseKey,landKey), feature(feature),level(level){} virtual ~VisionFactor(){} /// error function /// @param p the Estimated pose in Pose3 /// @param H the optional Jacobian matrix, which use boost optional and has default null pointer gtsam::Vector evaluateError(const gtsam::Pose3& p,const gtsam::Point3& l, boost::optional H1 = boost::none,boost::optional H2 = boost::none) const { // note that use boost optional like a pointer // only calculate jacobian matrix when non-null pointer exists gtsam::Matrix26 J1; gtsam::Matrix23 J2; gtsam::Point3 point(p*l); svo::Frame::jacobian_xyz2uv(point, J1); svo::Frame::jacobian_l2uv(point, J2); Vector2d e=(vk::project2d(feature) - vk::project2d(point))*1.0 / (1<( gtsam::NonlinearFactor::shared_ptr(new VisionFactor(*this))); } }; } // namespace gtsamexamples #endif //SVO_SVOVISIONFACTOR_H