utils.cpp
Go to the documentation of this file.
00001 //part of the source code of master thesis, source code produced by Jiri Divis
00008 #include "utils.h"
00009 #include <opencv2/core/core.hpp>
00010 #include <opencv2/imgproc/imgproc.hpp>
00011 #include <opencv2/highgui/highgui.hpp>
00012 #include <opencv2/features2d/features2d.hpp>
00013 #include <opencv2/calib3d/calib3d.hpp>
00014 #include <boost/random.hpp>
00015 
00016 boost::mt19937 gen;
00017 boost::mt19937 rng_mt19937; 
00018 
00019 ImageMatchVec imageMatchCoords(const vector<cv::KeyPoint> & tkpts, const vector<cv::KeyPoint> & qkpts,
00020         const std::vector<cv::DMatch> &matches){
00021     ALIGNED<ImageMatch>::vector spherical_matches;
00022     for(unsigned int i = 0 ; i < matches.size() ; i ++){
00023         cv::KeyPoint qkp = qkpts[matches[i].queryIdx];
00024         cv::KeyPoint tkp = tkpts[matches[i].trainIdx];
00025         Eigen::Vector3d qpt = (PanoImCoord::fromPixel(Vector2d(qkp.pt.x, qkp.pt.y))).getHomogenous();
00026         Eigen::Vector3d tpt = (PanoImCoord::fromPixel(Vector2d(tkp.pt.x, tkp.pt.y))).getHomogenous();
00027         spherical_matches.push_back(std::pair<Vector3d, Vector3d>(tpt, qpt));
00028     }
00029     return spherical_matches;
00030 }
00031 
00032 
00033 void points3dSTLToPointMatrix(const Points3dSTL & pts, PointMatrix & ptmat){
00034     for(Points3dSTL::size_type i = 0; i<pts.size(); i++){
00035         ptmat.block<3,1>(0, i) = pts[i];
00036     }
00037 }
00038 
00039 ImageMatchVec buildImageMatchesFrom3dPoints(
00040         const SE3 & T_wc1, const SE3 & T_wc2, const Points3dSTL & points){
00041     ImageMatchVec matches;
00042     for (unsigned int i = 0; i < points.size(); i++){
00043         matches.push_back(ImageMatch(T_wc1*points[i], T_wc2*points[i]));
00044     }
00045     return matches;
00046 }
00047 
00048 Points3dSTL projectPoints(SE3 T_sd, const Points3dSTL & points){
00049     Points3dSTL res;
00050     for(Points3dSTL::const_iterator it = points.begin(); it != points.end(); it++){
00051         Vector3d pt = *it;
00052         res.push_back(T_sd*pt);
00053     }
00054     return res;
00055 }
00056 
00057 
00058 double calculateVolume( const Vector3d & upper_left_deep, const Vector3d & bottom_right_shallow){
00059      Vector3d tmp = bottom_right_shallow - upper_left_deep;
00060      return abs(tmp(0)*tmp(1)*tmp(2));
00061 }
00062 
00063 
00064 
00065 void generateRandomScene(
00066         const Vector3d & upper_left_deep,
00067         const Vector3d & bottom_right_shallow,
00068         double target_num_vec,
00069         Points3dSTL & points){
00070     vector<boost::uniform_real<> > uniform;
00071     for(int i=0; i<3;i++){
00072         double a = upper_left_deep(i);
00073         double b = bottom_right_shallow(i);
00074         if(a < b){
00075             uniform.push_back(boost::uniform_real<>(a, b));
00076         } else{
00077             uniform.push_back(boost::uniform_real<>(b, a));
00078         }
00079     }
00080     for(int j=0; j < target_num_vec; j++){
00081         Vector3d vec;
00082         for(int i=0; i < 3 ; i++){
00083             vec(i) = uniform[i](gen);
00084         }
00085         points.push_back(vec);
00086     }
00087 }
00088 
00089 
00090 void generateRandomTrajectory(
00091         const Vector3d & upper_left_deep,
00092         const Vector3d & bottom_right_shallow,
00093         int num_stops,
00094         ALIGNED<SE3>::vector & transforms){ //T_wcx transforms for each pose
00095     Points3dSTL poses;
00096     Points3dSTL orientations;
00097     generateRandomScene(upper_left_deep, bottom_right_shallow, num_stops, poses);
00098     generateRandomScene(Vector3d::Zero(), Vector3d(2*M_PI, 2*M_PI, 2*M_PI), num_stops, orientations);
00099     transforms.push_back(SE3());
00100     for(int i=0; i<num_stops; i++){
00101         Vector3d tmp = orientations[i];
00102         transforms.push_back(SE3(SO3(tmp(0), tmp(1), tmp(2)), poses[i]).inverse());
00103     }
00104 }
00105 
00106 
00107 bool isApprox(double num, double target_num, double error){
00108     Matrix<double, 1, 1> m;
00109     m(0,0) = num - target_num;
00110     return m.isZero(error);
00111 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


pose_estimation
Author(s): Jiri Divis/jiridivis@gmail.com
autogenerated on Wed Mar 27 2013 21:00:12