00001 #ifndef RGBD_SLAM_MISC_H_
00002 #define RGBD_SLAM_MISC_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <QMatrix4x4>
00019 #include <tf/transform_datatypes.h>
00020 #include <sensor_msgs/Image.h>
00021 #include <sensor_msgs/CameraInfo.h>
00022 #include <cv.h>
00023 #include "point_types.h"
00024 #include "g2o/types/slam3d/vertex_se3.h"
00025
00027 void overlay_edges(cv::Mat visual, cv::Mat depth, cv::Mat& visual_edges, cv::Mat& depth_edges);
00029 void printTransform(const char* name, const tf::Transform t) ;
00031 void printTransform(const char* name, const tf::StampedTransform t) ;
00033 void logTransform(QTextStream& out, const tf::Transform& t, double timestamp, const char* label = NULL);
00034 void printQMatrix4x4(const char* name, const QMatrix4x4& m);
00035
00037 QMatrix4x4 g2o2QMatrix(const g2o::SE3Quat se3) ;
00039 tf::Transform g2o2TF( const g2o::SE3Quat se3) ;
00040 template <typename T >
00041 QMatrix4x4 eigenTF2QMatrix(const T& transf)
00042 {
00043 Eigen::Matrix<qreal, 4, 4, Eigen::RowMajor> m = transf.matrix();
00044 QMatrix4x4 qmat( static_cast<qreal*>( m.data() ) );
00045 printQMatrix4x4("From Eigen::Transform", qmat);
00046 return qmat;
00047 }
00048
00049 template <typename T >
00050 tf::Transform eigenTransf2TF(const T& transf)
00051 {
00052 tf::Transform result;
00053 tf::Vector3 translation;
00054 translation.setX(transf.translation().x());
00055 translation.setY(transf.translation().y());
00056 translation.setZ(transf.translation().z());
00057
00058 tf::Quaternion rotation;
00059 Eigen::Quaterniond quat;
00060 quat = transf.rotation();
00061 rotation.setX(quat.x());
00062 rotation.setY(quat.y());
00063 rotation.setZ(quat.z());
00064 rotation.setW(quat.w());
00065
00066 result.setOrigin(translation);
00067 result.setRotation(rotation);
00068
00069 return result;
00070 }
00072 g2o::SE3Quat eigen2G2O( const Eigen::Matrix4d& eigen_mat);
00074 g2o::SE3Quat tf2G2O( const tf::Transform t);
00075
00077 void mat2components(const Eigen::Matrix4f& t, double& roll, double& pitch, double& yaw, double& dist);
00079 void mat2RPY(const Eigen::Matrix4f& t, double& roll, double& pitch, double& yaw);
00081 void mat2dist(const Eigen::Matrix4f& t, double &dist);
00082
00083
00085 pointcloud_type* createXYZRGBPointCloud (const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::ImageConstPtr& rgb_msg, const sensor_msgs::CameraInfoConstPtr& cam_info);
00086 pointcloud_type* createXYZRGBPointCloud (const cv::Mat& depth_msg, const cv::Mat& rgb_msg, const sensor_msgs::CameraInfoConstPtr& cam_info);
00087
00088 #ifndef HEMACLOUDS
00089
00090
00091 void transformAndAppendPointCloud (const pointcloud_type &cloud_in, pointcloud_type &cloud_to_append_to,
00092 const tf::Transform transformation, float Max_Depth, int idx=0);
00093
00094 #else
00095
00096 void transformAndAppendPointCloud (const pointcloud_type &cloud_in,
00097 pcl::PointCloud<hema::PointXYZRGBCamSL> &cloud_to_append_to,
00098 const tf::Transform transformation, float max_Depth, int idx);
00099 #endif
00100
00101
00102 geometry_msgs::Point pointInWorldFrame(const Eigen::Vector4f& point3d, const g2o::VertexSE3::EstimateType& transf);
00103
00104
00105
00106 bool isBigTrafo(const Eigen::Isometry3d& t);
00107 bool isBigTrafo(const g2o::SE3Quat& t);
00109 bool isSmallTrafo(const g2o::SE3Quat& t, double seconds = 1.0);
00110 bool isSmallTrafo(const Eigen::Isometry3d& t, double seconds = 1.0);
00111
00112
00113
00114
00115
00116
00118 void depthToCV8UC1(cv::Mat& float_img, cv::Mat& mono8_img);
00119
00121 std::string openCVCode2String(unsigned int code);
00122
00124 void printMatrixInfo(const cv::Mat& image, std::string name = std::string(""));
00125
00127 bool asyncFrameDrop(ros::Time depth, ros::Time rgb);
00128
00129 double errorFunction(const Eigen::Vector4f& x1, const double x1_depth_cov,
00130 const Eigen::Vector4f& x2, const double x2_depth_cov,
00131 const Eigen::Matrix4f& tf_1_to_2);
00132
00133 double errorFunction2(const Eigen::Vector4f& x1,
00134 const Eigen::Vector4f& x2,
00135 const Eigen::Matrix4d& tf_1_to_2);
00136
00137 float getMinDepthInNeighborhood(const cv::Mat& depth, cv::Point2f center, float diameter);
00138
00139 void observationLikelihood(const Eigen::Matrix4f& proposed_transformation,
00140 pointcloud_type::Ptr new_pc,
00141 pointcloud_type::Ptr old_pc,
00142 const sensor_msgs::CameraInfo& old_cam_info,
00143 double& likelihood,
00144 double& confidence,
00145 unsigned int& inliers,
00146 unsigned int& outliers,
00147 unsigned int& occluded,
00148 unsigned int& all) ;
00149
00153 double rejectionSignificance(const Eigen::Matrix4f& proposed_transformation,
00154 pointcloud_type::Ptr new_pc,
00155 pointcloud_type::Ptr old_pc);
00156
00158 bool observation_criterion_met(unsigned int inliers, unsigned int outliers, unsigned int all, double& quality);
00159
00160
00161
00162
00163
00164 void getColor(const point_type& p, unsigned char& r, unsigned char& g, unsigned char& b);
00165 #endif