processor.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 * 
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 * 
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 * 
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 * 
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
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   // Disparity pre-filtering parameters
00086 
00087   int getPreFilterSize() const;
00088   void setPreFilterSize(int size);
00089 
00090   int getPreFilterCap() const;
00091   void setPreFilterCap(int cap);
00092 
00093   // Disparity correlation parameters
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); // Number of pixels to search
00103 
00104   // Disparity post-filtering parameters
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   // Do all the work!
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_; // scratch buffer for 16-bit signed disparity image
00141   mutable cv::StereoBM block_matcher_; // contains scratch buffers for block matching
00142   // scratch buffers for speckle filtering
00143   mutable cv::Mat_<uint32_t> labels_;
00144   mutable cv::Mat_<uint32_t> wavefront_;
00145   mutable cv::Mat_<uint8_t> region_types_;
00146   // scratch buffer for dense point cloud
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 } //namespace stereo_image_proc
00252 
00253 #endif


stereo_image_proc
Author(s): Patrick Mihelich, Kurt Konolige, Jeremy Leibs
autogenerated on Mon Oct 6 2014 00:46:19