diff --git a/include/msckf_vio/feature.hpp b/include/msckf_vio/feature.hpp index 0e8979c..c430216 100644 --- a/include/msckf_vio/feature.hpp +++ b/include/msckf_vio/feature.hpp @@ -788,32 +788,24 @@ cv::Point2f Feature::pixelDistanceAt( Eigen::Vector3d& in_p) const { - Eigen::Isometry3d T_c0_w; - - cv::Point2f out_p; - cv::Point2f cam_p = projectPositionToCamera(cam_state, cam_state_id, cam, in_p); - - cv::Point2f surroundingPoint; // create vector of patch in pixel plane - surroundingPoint = cv::Point2f(cam_p.x+1, cam_p.y+1); + std::vector surroundingPoints; + surroundingPoints.push_back(cv::Point2f(cam_p.x+1, cam_p.y)); + surroundingPoints.push_back(cv::Point2f(cam_p.x-1, cam_p.y)); + surroundingPoints.push_back(cv::Point2f(cam_p.x, cam_p.y+1)); + surroundingPoints.push_back(cv::Point2f(cam_p.x, cam_p.y-1)); - cv::Point2f pure_surroundingPoint; - image_handler::undistortPoint(surroundingPoint, + std::vector pure; + image_handler::undistortPoints(surroundingPoints, cam.intrinsics, cam.distortion_model, - cam.distortion_coeffs, - pure_surroundingPoint); + cam.distortion_coeffs, + pure); - cv::Point2f pure_Point; - image_handler::undistortPoint(cam_p, - cam.intrinsics, - cam.distortion_model, - cam.distortion_coeffs, - pure_Point); - - cv::Point2f distance(fabs(pure_surroundingPoint.x - pure_Point.x), fabs(pure_surroundingPoint.y - pure_Point.y)); + // returns the absolute pixel distance at pixels one metres away + cv::Point2f distance(fabs(pure[0].x - pure[1].x), fabs(pure[2].y - pure[3].y)); return distance; } diff --git a/launch/msckf_vio_tum.launch b/launch/msckf_vio_tum.launch index 0fc464a..a28de3f 100644 --- a/launch/msckf_vio_tum.launch +++ b/launch/msckf_vio_tum.launch @@ -21,7 +21,7 @@ - + diff --git a/src/msckf_vio.cpp b/src/msckf_vio.cpp index 5d7d4c2..3968190 100644 --- a/src/msckf_vio.cpp +++ b/src/msckf_vio.cpp @@ -1225,6 +1225,9 @@ void MsckfVio::PhotometricMeasurementJacobian( const CAMState& cam_state = state_server.cam_states[cam_state_id]; const Feature& feature = map_server[feature_id]; + const StateIDType anchor_state_id = feature.observations.begin()->first; + const CAMState anchor_state = state_server.cam_states[anchor_state_id]; + // Cam0 pose. Matrix3d R_w_c0 = quaternionToRotation(cam_state.orientation); const Vector3d& t_c0_w = cam_state.position; @@ -1253,16 +1256,19 @@ void MsckfVio::PhotometricMeasurementJacobian( { Eigen::Vector3d p_c0 = R_w_c0 * (point-t_c0_w); cv::Point2f p_in_c0 = feature.projectPositionToCamera(cam_state, cam_state_id, cam0, point); - + cv::Point2f p_in_anchor = feature.projectPositionToCamera(anchor_state, anchor_state_id, cam0, point); Matrix dI_dhj = Matrix::Zero(); // add jacobians + cv::Point2f pixelDistance = feature.pixelDistanceAt(anchor_state, anchor_state_id, cam0, point); - cv::Point2f pixelDistance = feature.pixelDistanceAt(cam_state, cam_state_id, cam0, point); - + std::cout << "pixelDistance: \n" << pixelDistance << std::endl; + + + // calculate derivation for anchor frame, use position for derivation calculation // frame derivative calculated convoluting with kernel [-1, 0, 1] - dx = feature.PixelIrradiance(cv::Point2f(p_in_c0.x+1, p_in_c0.y), frame) - feature.PixelIrradiance(cv::Point2f(p_in_c0.x-1, p_in_c0.y), frame); - dy = feature.PixelIrradiance(cv::Point2f(p_in_c0.x, p_in_c0.y+1), frame) - feature.PixelIrradiance(cv::Point2f(p_in_c0.x, p_in_c0.y-1), frame); + dx = feature.PixelIrradiance(cv::Point2f(p_in_anchor.x+1, p_in_anchor.y), frame) - feature.PixelIrradiance(cv::Point2f(p_in_anchor.x-1, p_in_anchor.y), frame); + dy = feature.PixelIrradiance(cv::Point2f(p_in_anchor.x, p_in_anchor.y+1), frame) - feature.PixelIrradiance(cv::Point2f(p_in_anchor.x, p_in_anchor.y-1), frame); dI_dhj(0, 0) = dx/pixelDistance.x; dI_dhj(0, 1) = dy/pixelDistance.y; @@ -1690,6 +1696,7 @@ void MsckfVio::measurementUpdate(const MatrixXd& H, const VectorXd& r) { } bool MsckfVio::gatingTest(const MatrixXd& H, const VectorXd& r, const int& dof) { + return true; MatrixXd P1 = H * state_server.state_cov * H.transpose();