20 #ifndef DENSE_MAP_UTILS_H_
21 #define DENSE_MAP_UTILS_H_
23 #include <opencv2/calib3d/calib3d.hpp>
24 #include <opencv2/imgproc.hpp>
25 #include <opencv2/imgcodecs.hpp>
26 #include <opencv2/highgui.hpp>
27 #include <opencv2/core/utility.hpp>
30 #include <Eigen/Geometry>
32 #include <config_reader/config_reader.h>
33 #include <camera/camera_params.h>
35 #include <boost/shared_ptr.hpp>
44 const int NUM_SCALAR_PARAMS = 1;
45 const int NUM_OPT_CTR_PARAMS = 2;
46 const int NUM_PIX_PARAMS = 2;
47 const int NUM_XYZ_PARAMS = 3;
48 const int NUM_RIGID_PARAMS = 7;
49 const int NUM_AFFINE_PARAMS = 12;
53 void parse_intrinsics_to_float(std::string
const& intrinsics_to_float,
54 std::set<std::string>& intrinsics_to_float_set);
58 void parse_extrinsics_to_float(std::vector<std::string>
const& cam_names,
59 std::string
const& ref_cam_name,
60 std::string
const& depth_to_image_name,
61 std::string
const& extrinsics_to_float,
62 std::set<std::string>& extrinsics_to_float_set);
65 void rigid_transform_to_array(Eigen::Affine3d
const& aff,
double* arr);
69 void array_to_rigid_transform(Eigen::Affine3d& aff,
const double* arr);
71 void affine_transform_to_array(Eigen::Affine3d
const& aff,
double* arr);
72 void array_to_affine_transform(Eigen::Affine3d& aff,
const double* arr);
75 std::vector<double> string_to_vector(std::string
const& str);
78 void readPoseMatrix(cv::Mat& pose, std::string
const& filename);
81 bool readAffine(Eigen::Affine3d& T, std::string
const& filename);
84 void writeMatrix(Eigen::MatrixXd
const& M, std::string
const& filename);
86 void writeCloud(std::vector<float>
const& points,
size_t point_size, std::string
const& filename);
89 std::string matType(cv::Mat
const& mat);
92 void readCameraTransform(config_reader::ConfigReader& config, std::string
const transform_str,
93 Eigen::Affine3d& transform);
98 std::vector<std::string>
const& cam_names,
99 std::string
const& nav_cam_to_body_trans_str,
100 std::string
const& haz_cam_depth_to_image_trans_str,
102 std::vector<camera::CameraParameters> & cam_params,
103 std::vector<Eigen::Affine3d> & nav_to_cam_trans,
104 std::vector<double> & nav_to_cam_timestamp_offset,
105 Eigen::Affine3d & nav_cam_to_body_trans,
106 Eigen::Affine3d & haz_cam_depth_to_image_trans);
110 void updateConfigFile
111 (std::vector<std::string>
const& cam_names,
112 std::string
const& haz_cam_depth_to_image_trans_str,
113 std::vector<camera::CameraParameters>
const& cam_params,
114 std::vector<Eigen::Affine3d>
const& nav_to_cam_trans,
115 std::vector<double>
const& nav_to_cam_timestamp_offset,
116 Eigen::Affine3d
const& haz_cam_depth_to_image_trans);
119 Eigen::Affine3d linearInterp(
double alpha, Eigen::Affine3d
const& aff0,
120 Eigen::Affine3d
const& aff1);
125 bool findInterpPose(
double desired_time, std::map<double, Eigen::Affine3d>
const& poses,
126 Eigen::Affine3d& interp_pose);
131 double maxRotationAngle(Eigen::Affine3d
const& T);
141 void addPose(Eigen::Affine3d
const& pose,
double timestamp);
147 bool interpPose(
double input_timestamp,
double max_gap, Eigen::Affine3d& out_pose)
const;
154 std::map<int, std::map<double, Eigen::Affine3d> > m_poses;
158 void normalToAzimuthAndElevation(Eigen::Vector3d
const& normal,
double& azimuth,
double& elevation);
161 void azimuthAndElevationToNormal(Eigen::Vector3d& normal,
double azimuth,
double elevation);
165 void snapPlaneNormal(Eigen::Vector3d& plane_normal);
168 void bestFitPlane(
const std::vector<Eigen::Vector3d>& points, Eigen::Vector3d& centroid, Eigen::Vector3d& plane_normal);
171 double fileNameToTimestamp(std::string
const& file_name);
174 void createDir(std::string
const& dir);
178 std::map<double, double> haz_depth_to_image_timestamps;
179 std::map<std::string, std::map<double, Eigen::Affine3d> > world_to_cam_poses;
184 void writeCameraPoses(std::string
const& filename, std::map<double, double>
const& haz_depth_to_image_timestamps,
185 std::map<std::string, std::map<double, Eigen::Affine3d> >
const& world_to_cam_poses);
187 void readCameraPoses(std::string
const& filename, std::map<double, double>& haz_depth_to_image_timestamps,
188 std::map<std::string, std::map<double, Eigen::Affine3d> >& world_to_cam_poses);
192 double gamma(
double x);
193 double inv_gamma(
double x);
198 void exposureCorrection(
double max_iso_times_exposure,
double iso,
double exposure, cv::Mat
const& input_image,
199 cv::Mat& output_image);
204 void scaleImage(
double max_iso_times_exposure,
double iso,
double exposure, cv::Mat
const& input_image,
205 cv::Mat& output_image);
213 void pickTimestampsInBounds(std::vector<double>
const& timestamps,
double left_bound,
double right_bound,
double offset,
214 std::vector<double>& out_timestamps);
217 enum ExifData { TIMESTAMP = 0, EXPOSURE_TIME, ISO, APERTURE, FOCAL_LENGTH, NUM_EXIF };
222 void save_tsai_camera(Eigen::MatrixXd
const& desired_cam_to_world_trans,
223 std::string
const& output_dir,
224 double curr_time, std::string
const& suffix);
228 #endif // DENSE_MAP_UTILS_H_