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
00031
00032
00033
00034 #ifndef STEREO_IMAGE_PROC_PROCESSOR_H
00035 #define STEREO_IMAGE_PROC_PROCESSOR_H
00036
00037 #include <image_proc/processor.h>
00038 #include <image_geometry/stereo_camera_model.h>
00039 #include <stereo_msgs/DisparityImage.h>
00040 #include <sensor_msgs/PointCloud.h>
00041 #include <sensor_msgs/PointCloud2.h>
00042
00043 namespace stereo_image_proc {
00044
00045 struct StereoImageSet
00046 {
00047 image_proc::ImageSet left;
00048 image_proc::ImageSet right;
00049 stereo_msgs::DisparityImage disparity;
00050 sensor_msgs::PointCloud points;
00051 sensor_msgs::PointCloud2 points2;
00052 };
00053
00054 class StereoProcessor
00055 {
00056 public:
00057
00058 StereoProcessor()
00059 : block_matcher_(cv::StereoBM::BASIC_PRESET)
00060 {
00061 }
00062
00063 enum {
00064 LEFT_MONO = 1 << 0,
00065 LEFT_RECT = 1 << 1,
00066 LEFT_COLOR = 1 << 2,
00067 LEFT_RECT_COLOR = 1 << 3,
00068 RIGHT_MONO = 1 << 4,
00069 RIGHT_RECT = 1 << 5,
00070 RIGHT_COLOR = 1 << 6,
00071 RIGHT_RECT_COLOR = 1 << 7,
00072 DISPARITY = 1 << 8,
00073 POINT_CLOUD = 1 << 9,
00074 POINT_CLOUD2 = 1 << 10,
00075
00076 LEFT_ALL = LEFT_MONO | LEFT_RECT | LEFT_COLOR | LEFT_RECT_COLOR,
00077 RIGHT_ALL = RIGHT_MONO | RIGHT_RECT | RIGHT_COLOR | RIGHT_RECT_COLOR,
00078 STEREO_ALL = DISPARITY | POINT_CLOUD | POINT_CLOUD2,
00079 ALL = LEFT_ALL | RIGHT_ALL | STEREO_ALL
00080 };
00081
00082 int getInterpolation() const;
00083 void setInterpolation(int interp);
00084
00085
00086
00087 int getPreFilterSize() const;
00088 void setPreFilterSize(int size);
00089
00090 int getPreFilterCap() const;
00091 void setPreFilterCap(int cap);
00092
00093
00094
00095 int getCorrelationWindowSize() const;
00096 void setCorrelationWindowSize(int size);
00097
00098 int getMinDisparity() const;
00099 void setMinDisparity(int min_d);
00100
00101 int getDisparityRange() const;
00102 void setDisparityRange(int range);
00103
00104
00105
00106 int getTextureThreshold() const;
00107 void setTextureThreshold(int threshold);
00108
00109 float getUniquenessRatio() const;
00110 void setUniquenessRatio(float ratio);
00111
00112 int getSpeckleSize() const;
00113 void setSpeckleSize(int size);
00114
00115 int getSpeckleRange() const;
00116 void setSpeckleRange(int range);
00117
00118
00119 bool process(const sensor_msgs::ImageConstPtr& left_raw,
00120 const sensor_msgs::ImageConstPtr& right_raw,
00121 const image_geometry::StereoCameraModel& model,
00122 StereoImageSet& output, int flags) const;
00123
00124 void processDisparity(const cv::Mat& left_rect, const cv::Mat& right_rect,
00125 const image_geometry::StereoCameraModel& model,
00126 stereo_msgs::DisparityImage& disparity) const;
00127
00128 void processPoints(const stereo_msgs::DisparityImage& disparity,
00129 const cv::Mat& color, const std::string& encoding,
00130 const image_geometry::StereoCameraModel& model,
00131 sensor_msgs::PointCloud& points) const;
00132 void processPoints2(const stereo_msgs::DisparityImage& disparity,
00133 const cv::Mat& color, const std::string& encoding,
00134 const image_geometry::StereoCameraModel& model,
00135 sensor_msgs::PointCloud2& points) const;
00136
00137 private:
00138 image_proc::Processor mono_processor_;
00139
00140 mutable cv::Mat_<int16_t> disparity16_;
00141 mutable cv::StereoBM block_matcher_;
00142
00143 mutable cv::Mat_<uint32_t> labels_;
00144 mutable cv::Mat_<uint32_t> wavefront_;
00145 mutable cv::Mat_<uint8_t> region_types_;
00146
00147 mutable cv::Mat_<cv::Vec3f> dense_points_;
00148 };
00149
00150
00151 inline int StereoProcessor::getInterpolation() const
00152 {
00153 return mono_processor_.interpolation_;
00154 }
00155
00156 inline void StereoProcessor::setInterpolation(int interp)
00157 {
00158 mono_processor_.interpolation_ = interp;
00159 }
00160
00161 inline int StereoProcessor::getPreFilterSize() const
00162 {
00163 return block_matcher_.state->preFilterSize;
00164 }
00165
00166 inline void StereoProcessor::setPreFilterSize(int size)
00167 {
00168 block_matcher_.state->preFilterSize = size;
00169 }
00170
00171 inline int StereoProcessor::getPreFilterCap() const
00172 {
00173 return block_matcher_.state->preFilterCap;
00174 }
00175
00176 inline void StereoProcessor::setPreFilterCap(int cap)
00177 {
00178 block_matcher_.state->preFilterCap = cap;
00179 }
00180
00181 inline int StereoProcessor::getCorrelationWindowSize() const
00182 {
00183 return block_matcher_.state->SADWindowSize;
00184 }
00185
00186 inline void StereoProcessor::setCorrelationWindowSize(int size)
00187 {
00188 block_matcher_.state->SADWindowSize = size;
00189 }
00190
00191 inline int StereoProcessor::getMinDisparity() const
00192 {
00193 return block_matcher_.state->minDisparity;
00194 }
00195
00196 inline void StereoProcessor::setMinDisparity(int min_d)
00197 {
00198 block_matcher_.state->minDisparity = min_d;
00199 }
00200
00201 inline int StereoProcessor::getDisparityRange() const
00202 {
00203 return block_matcher_.state->numberOfDisparities;
00204 }
00205
00206 inline void StereoProcessor::setDisparityRange(int range)
00207 {
00208 block_matcher_.state->numberOfDisparities = range;
00209 }
00210
00211 inline int StereoProcessor::getTextureThreshold() const
00212 {
00213 return block_matcher_.state->textureThreshold;
00214 }
00215
00216 inline void StereoProcessor::setTextureThreshold(int threshold)
00217 {
00218 block_matcher_.state->textureThreshold = threshold;
00219 }
00220
00221 inline float StereoProcessor::getUniquenessRatio() const
00222 {
00223 return block_matcher_.state->uniquenessRatio;
00224 }
00225
00226 inline void StereoProcessor::setUniquenessRatio(float ratio)
00227 {
00228 block_matcher_.state->uniquenessRatio = ratio;
00229 }
00230
00231 inline int StereoProcessor::getSpeckleSize() const
00232 {
00233 return block_matcher_.state->speckleWindowSize;
00234 }
00235
00236 inline void StereoProcessor::setSpeckleSize(int size)
00237 {
00238 block_matcher_.state->speckleWindowSize = size;
00239 }
00240
00241 inline int StereoProcessor::getSpeckleRange() const
00242 {
00243 return block_matcher_.state->speckleRange;
00244 }
00245
00246 inline void StereoProcessor::setSpeckleRange(int range)
00247 {
00248 block_matcher_.state->speckleRange = range;
00249 }
00250
00251 }
00252
00253 #endif