added position calculation
This commit is contained in:
@ -16,6 +16,8 @@
|
||||
#include <Eigen/Geometry>
|
||||
#include <Eigen/StdVector>
|
||||
|
||||
#include "image_handler.h"
|
||||
|
||||
#include "math_utils.hpp"
|
||||
#include "imu_state.h"
|
||||
#include "cam_state.h"
|
||||
@ -123,8 +125,11 @@ struct Feature {
|
||||
* @return True if the Anchor can be estimated
|
||||
*/
|
||||
|
||||
inline bool initializeAnchor(
|
||||
const movingWindow& cam0_moving_window);
|
||||
bool initializeAnchor(
|
||||
const movingWindow& cam0_moving_window,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs);
|
||||
|
||||
|
||||
/*
|
||||
@ -141,6 +146,15 @@ struct Feature {
|
||||
inline bool initializePosition(
|
||||
const CamStateServer& cam_states);
|
||||
|
||||
/*
|
||||
* @brief projectPixelToPosition uses the calcualted pixels
|
||||
* of the anchor patch to generate 3D positions of all of em
|
||||
*/
|
||||
bool projectPixelToPosition(cv::Point2f in_p,
|
||||
Eigen::Vector3d& out_p,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs);
|
||||
|
||||
// An unique identifier for the feature.
|
||||
// In case of long time running, the variable
|
||||
@ -159,9 +173,16 @@ struct Feature {
|
||||
|
||||
// NxN Patch of Anchor Image
|
||||
std::vector<double> anchorPatch;
|
||||
|
||||
// Position of NxN Patch in 3D space
|
||||
std::vector<Eigen::Vector3d> anchorPatch_3d;
|
||||
|
||||
// 3d postion of the feature in the world frame.
|
||||
Eigen::Vector3d position;
|
||||
|
||||
// inverse depth representation
|
||||
double rho;
|
||||
|
||||
// A indicator to show if the 3d postion of the feature
|
||||
// has been initialized or not.
|
||||
bool is_initialized;
|
||||
@ -305,8 +326,24 @@ bool Feature::checkMotion(
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Feature::projectPixelToPosition(cv::Point2f in_p,
|
||||
Eigen::Vector3d& out_p,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs)
|
||||
{
|
||||
// use undistorted position of point of interest
|
||||
// project it back into 3D space using pinhole model
|
||||
// save resulting NxN positions for this feature
|
||||
anchorPatch_3d.push_back(Eigen::Vector3d(in_p.x/rho, in_p.y/rho, 1/rho));
|
||||
printf("%f, %f, %f\n",in_p.x/rho, in_p.y/rho, 1/rho);
|
||||
}
|
||||
|
||||
bool Feature::initializeAnchor(
|
||||
const movingWindow& cam0_moving_window)
|
||||
const movingWindow& cam0_moving_window,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs)
|
||||
{
|
||||
|
||||
int N = 5;
|
||||
@ -317,15 +354,25 @@ bool Feature::initializeAnchor(
|
||||
return false;
|
||||
|
||||
cv::Mat anchorImage = cam0_moving_window.find(anchor->first)->second;
|
||||
auto u = anchor->second(0)*anchorImage.rows/2 + anchorImage.rows/2;
|
||||
auto v = anchor->second(1)*anchorImage.cols/2 + anchorImage.cols/2;
|
||||
auto u = anchor->second(0)*intrinsics[0] + intrinsics[2];
|
||||
auto v = anchor->second(1)*intrinsics[1] + intrinsics[3];
|
||||
int count = 0;
|
||||
|
||||
for(int u_run = (int)u - n; u_run <= (int)u + n; u_run++)
|
||||
for(int v_run = v - n; v_run <= v + n; v_run++)
|
||||
anchorPatch.push_back(anchorImage.at<uint8_t>(u_run,v_run));
|
||||
|
||||
return true;
|
||||
printf("estimated NxN position: \n");
|
||||
for(double u_run = u - n; u_run <= u + n; u_run = u_run + 1)
|
||||
{
|
||||
for(double v_run = v - n; v_run <= v + n; v_run = v_run + 1)
|
||||
{
|
||||
anchorPatch.push_back(anchorImage.at<uint8_t>((int)u_run,(int)v_run));
|
||||
Eigen::Vector3d Npose;
|
||||
projectPixelToPosition(cv::Point2f((u_run-intrinsics[2])/intrinsics[0], (v_run-intrinsics[1])/intrinsics[3]),
|
||||
Npose,
|
||||
intrinsics,
|
||||
distortion_model,
|
||||
distortion_coeffs);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Feature::initializePosition(
|
||||
@ -465,6 +512,9 @@ bool Feature::initializePosition(
|
||||
}
|
||||
}
|
||||
|
||||
//save inverse depth distance from camera
|
||||
rho = solution(2);
|
||||
|
||||
// Convert the feature position to the world frame.
|
||||
position = T_c0_w.linear()*final_position + T_c0_w.translation();
|
||||
|
||||
|
34
include/msckf_vio/image_handler.h
Normal file
34
include/msckf_vio/image_handler.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef MSCKF_VIO_IMAGE_HANDLER_H
|
||||
#define MSCKF_VIO_IMAGE_HANDLER_H
|
||||
|
||||
#include <ros/ros.h>
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/video.hpp>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <Eigen/Geometry>
|
||||
#include <vector>
|
||||
|
||||
namespace msckf_vio {
|
||||
/*
|
||||
* @brief utilities for msckf_vio
|
||||
*/
|
||||
namespace image_handler {
|
||||
|
||||
void undistortPoints(
|
||||
const std::vector<cv::Point2f>& pts_in,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs,
|
||||
std::vector<cv::Point2f>& pts_out,
|
||||
const cv::Matx33d &rectification_matrix = cv::Matx33d::eye(),
|
||||
const cv::Vec4d &new_intrinsics = cv::Vec4d(1,1,0,0));
|
||||
|
||||
std::vector<cv::Point2f> distortPoints(
|
||||
const std::vector<cv::Point2f>& pts_in,
|
||||
const cv::Vec4d& intrinsics,
|
||||
const std::string& distortion_model,
|
||||
const cv::Vec4d& distortion_coeffs);
|
||||
}
|
||||
}
|
||||
#endif
|
@ -205,6 +205,17 @@ class MsckfVio {
|
||||
movingWindow cam0_moving_window;
|
||||
movingWindow cam1_moving_window;
|
||||
|
||||
// Camera calibration parameters
|
||||
std::string cam0_distortion_model;
|
||||
cv::Vec2i cam0_resolution;
|
||||
cv::Vec4d cam0_intrinsics;
|
||||
cv::Vec4d cam0_distortion_coeffs;
|
||||
|
||||
std::string cam1_distortion_model;
|
||||
cv::Vec2i cam1_resolution;
|
||||
cv::Vec4d cam1_intrinsics;
|
||||
cv::Vec4d cam1_distortion_coeffs;
|
||||
|
||||
// Indicate if the gravity vector is set.
|
||||
bool is_gravity_set;
|
||||
|
||||
|
Reference in New Issue
Block a user