transformation_estimation_euclidean.cpp
Go to the documentation of this file.
00001 #include "transformation_estimation_euclidean.h"
00002 #include "node.h"
00003 #include <pcl/common/transformation_from_correspondences.h>
00004 #include <Eigen/Geometry>
00005 #include "parameter_server.h"
00006 
00007 Eigen::Matrix4f getTransformFromMatches(const Node* newer_node,
00008                                         const Node* earlier_node,
00009                                         const std::vector<cv::DMatch>& matches,
00010                                         bool& valid, 
00011                                         const float max_dist_m) 
00012 {
00013   pcl::TransformationFromCorrespondences tfc;
00014   valid = true;
00015   std::vector<Eigen::Vector3f> t, f;
00016   float weight = 1.0;
00017 
00018   BOOST_FOREACH(const cv::DMatch& m, matches)
00019   {
00020     Eigen::Vector3f from = newer_node->feature_locations_3d_[m.queryIdx].head<3>();
00021     Eigen::Vector3f to = earlier_node->feature_locations_3d_[m.trainIdx].head<3>();
00022     if(isnan(from(2)) || isnan(to(2)))
00023       continue;
00024 
00025     weight = 1.0/(from(2) * to(2));
00026 #ifdef HEMACLOUDS
00027     ParameterServer* ps = ParameterServer::instance();
00028 
00029     //Create point cloud inf necessary
00030     if(ps->get<int>("segment_to_optimize") > 0){
00031       weight =1/( earlier_node->feature_locations_3d_[m.trainIdx][3] \
00032                 + newer_node->feature_locations_3d_[m.queryIdx][3]);
00033     } else {
00034       weight =1/( earlier_node->feature_locations_3d_[m.trainIdx][2] \
00035                 + newer_node->feature_locations_3d_[m.queryIdx][2]);
00036     }
00037 #endif
00038     if(false){//is that code useful?
00039       //Validate that 3D distances are corresponding
00040       if (max_dist_m > 0) {  //storing is only necessary, if max_dist is given
00041         if(f.size() >= 1)
00042         {
00043           float delta_f = (from - f.back()).squaredNorm();//distance to the previous query point
00044           float delta_t = (to   - t.back()).squaredNorm();//distance from one to the next train point
00045 
00046           if ( abs(delta_f-delta_t) > max_dist_m * max_dist_m ) {
00047             valid = false;
00048             return Eigen::Matrix4f();
00049           }
00050         }
00051         f.push_back(from);
00052         t.push_back(to);    
00053       }
00054     }
00055 
00056     tfc.add(from, to, weight);// 1.0/(to(2)*to(2)));//the further, the less weight b/c of quadratic accuracy decay
00057   }
00058 
00059   // get relative movement from samples
00060   return tfc.getTransformation().matrix();
00061 }
00062 
00063 Eigen::Matrix4f getTransformFromMatchesUmeyama(const Node* newer_node,
00064                                                const Node* earlier_node,
00065                                                std::vector<cv::DMatch> matches,
00066                                                bool& valid) 
00067 {
00068   Eigen::Matrix<float, 3, Eigen::Dynamic> tos(3,matches.size()), froms(3,matches.size());
00069   std::vector<cv::DMatch>::const_iterator it = matches.begin();
00070   for (int i = 0 ;it!=matches.end(); it++, i++) {
00071     Eigen::Vector3f f = newer_node->feature_locations_3d_[it->queryIdx].head<3>(); //Oh my god, c++
00072     Eigen::Vector3f t = earlier_node->feature_locations_3d_[it->trainIdx].head<3>();
00073     if(isnan(f(2)) || isnan(t(2)))
00074       continue;
00075     froms.col(i) = f;
00076     tos.col(i) = t;
00077   }
00078   Eigen::Matrix4f res = Eigen::umeyama(froms, tos, false);
00079   valid = !containsNaN(res);
00080   return res;
00081 }


rgbdslam_v2
Author(s): Felix Endres, Juergen Hess, Nikolas Engelhard
autogenerated on Thu Jun 6 2019 21:49:45