Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef DISCRETE_DEPTH_DISTORTION_MODEL_H
00031 #define DISCRETE_DEPTH_DISTORTION_MODEL_H
00032
00033 #include <assert.h>
00034 #include <vector>
00035 #include <set>
00036 #include <Eigen/Core>
00037 #include <opencv2/opencv.hpp>
00038 #include <rtabmap/utilite/UMutex.h>
00039 #include "rtabmap/core/RtabmapExp.h"
00040
00041 namespace clams
00042 {
00043 class RTABMAP_EXP DiscreteFrustum
00044 {
00045 public:
00046 DiscreteFrustum(int smoothing = 1, double bin_depth = 1.0, double max_dist = 10.0);
00049 void addExample(double ground_truth, double measurement);
00050 int index(double z) const;
00051 void undistort(double* z) const;
00052 void interpolatedUndistort(double* z) const;
00053 void serialize(std::ostream& out, bool ascii) const;
00054 void deserialize(std::istream& in, bool ascii);
00055
00056 protected:
00057 double max_dist_;
00058 int num_bins_;
00059 double bin_depth_;
00060 Eigen::VectorXf counts_;
00061 Eigen::VectorXf total_numerators_;
00062 Eigen::VectorXf total_denominators_;
00063 Eigen::VectorXf multipliers_;
00064
00065 friend class DiscreteDepthDistortionModel;
00066 };
00067
00068 class RTABMAP_EXP DiscreteDepthDistortionModel
00069 {
00070 public:
00071
00072 static std::set<size_t> getDivisors(const size_t &num);
00073
00074
00075 static size_t getClosestToRef(const std::set<size_t> &divisors, const double &ref);
00076
00077
00078 static void getBinSize(const size_t &width, const size_t &height, size_t &bin_width, size_t &bin_height);
00079
00080 public:
00081 DiscreteDepthDistortionModel() :
00082 width_(0),
00083 height_(0),
00084 bin_width_(0),
00085 bin_height_(0),
00086 bin_depth_(0),
00087 num_bins_x_(0),
00088 num_bins_y_(0),
00089 training_samples_(0)
00090 {}
00091 virtual ~DiscreteDepthDistortionModel();
00092 DiscreteDepthDistortionModel(int width, int height, int bin_width = 8, int bin_height = 6, double bin_depth = 2.0, int smoothing = 1, double max_depth = 10.0);
00093 DiscreteDepthDistortionModel(const DiscreteDepthDistortionModel& other);
00094 DiscreteDepthDistortionModel& operator=(const DiscreteDepthDistortionModel& other);
00095 void undistort(cv::Mat & depth) const;
00098 size_t accumulate(const cv::Mat& ground_truth, const cv::Mat& measurement);
00099 void addExample(int v, int u, double ground_truth, double measurement);
00100 void save(const std::string& path) const;
00101 void load(const std::string& path);
00102 void serialize(std::ostream& out, bool ascii) const;
00103 void deserialize(std::istream& in, bool ascii);
00104 cv::Mat visualize(const std::string& path = "") const;
00105
00106 int getWidth() const {return width_;}
00107 int getHeight() const {return height_;}
00108 size_t getTrainingSamples() const {return training_samples_;}
00109 bool isValid() const
00110 {
00111 return !frustums_.empty();
00112 }
00113
00114 protected:
00116 int width_;
00118 int height_;
00120 int bin_width_;
00122 int bin_height_;
00124 double bin_depth_;
00125 int num_bins_x_;
00126 int num_bins_y_;
00128 std::vector< std::vector<DiscreteFrustum*> > frustums_;
00129
00130 size_t training_samples_;
00131
00132 void deleteFrustums();
00133 DiscreteFrustum& frustum(int y, int x);
00134 const DiscreteFrustum& frustum(int y, int x) const;
00135
00136 UMutex mutex_;
00137 };
00138
00139 }
00140
00141 #endif // DISCRETE_DEPTH_DISTORTION_MODEL_H