Point Cloud Library (PCL)  1.9.1
disparity_map_converter.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2014-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 #ifndef PCL_DISPARITY_MAP_CONVERTER_H_
37 #define PCL_DISPARITY_MAP_CONVERTER_H_
38 
39 #include <cstring>
40 #include <vector>
41 
42 #include <pcl/point_cloud.h>
43 #include <pcl/point_types.h>
44 
45 namespace pcl
46 {
47  /** \brief Compute point cloud from the disparity map.
48  *
49  * Example of usage:
50  *
51  * \code
52  * pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new
53  * pcl::PointCloud<pcl::PointXYZI>);
54  * pcl::PointCloud<pcl::RGB>::Ptr left_image (new
55  * pcl::PointCloud<pcl::RGB>);
56  * // Fill left image cloud.
57  *
58  * pcl::DisparityMapConverter<pcl::PointXYZI> dmc;
59  * dmc.setBaseline (0.8387445f);
60  * dmc.setFocalLength (368.534700f);
61  * dmc.setImageCenterX (318.112200f);
62  * dmc.setImageCenterY (224.334900f);
63  * dmc.setDisparityThresholdMin(15.0f);
64  *
65  * // Left view of the scene.
66  * dmc.setImage (left_image);
67  * // Disparity map of the scene.
68  * dmc.loadDisparityMap ("disparity_map.txt", 640, 480);
69  *
70  * dmc.compute(*cloud);
71  * \endcode
72  *
73  * \author Timur Ibadov (ibadov.timur@gmail.com)
74  * \ingroup stereo
75  */
76  template <typename PointT>
78  {
79  protected:
81 
82  public:
83  /** \brief DisparityMapConverter constructor. */
85  /** \brief Empty destructor. */
86  virtual ~DisparityMapConverter ();
87 
88  /** \brief Set x-coordinate of the image center.
89  * \param[in] center_x x-coordinate of the image center.
90  */
91  inline void
92  setImageCenterX (const float center_x);
93 
94  /** \brief Get x-coordinate of the image center.
95  * \return x-coordinate of the image center.
96  */
97  inline float
98  getImageCenterX () const;
99 
100  /** \brief Set y-coordinate of the image center.
101  * \param[in] center_y y-coordinate of the image center.
102  */
103  inline void
104  setImageCenterY (const float center_y);
105 
106  /** \brief Get y-coordinate of the image center.
107  * \return y-coordinate of the image center.
108  */
109  inline float
110  getImageCenterY () const;
111 
112  /** \brief Set focal length.
113  * \param[in] focal_length the focal length.
114  */
115  inline void
116  setFocalLength (const float focal_length);
117 
118  /** \brief Get focal length.
119  * \return the focal length.
120  */
121  inline float
122  getFocalLength () const;
123 
124  /** \brief Set baseline.
125  * \param[in] baseline baseline.
126  */
127  inline void
128  setBaseline (const float baseline);
129 
130  /** \brief Get baseline.
131  * \return the baseline.
132  */
133  inline float
134  getBaseline () const;
135 
136  /** \brief Set min disparity threshold.
137  * \param[in] disparity_threshold_min min disparity threshold.
138  */
139  inline void
140  setDisparityThresholdMin (const float disparity_threshold_min);
141 
142  /** \brief Get min disparity threshold.
143  * \return min disparity threshold.
144  */
145  inline float
146  getDisparityThresholdMin () const;
147 
148  /** \brief Set max disparity threshold.
149  * \param[in] disparity_threshold_max max disparity threshold.
150  */
151  inline void
152  setDisparityThresholdMax (const float disparity_threshold_max);
153 
154  /** \brief Get max disparity threshold.
155  * \return max disparity threshold.
156  */
157  inline float
158  getDisparityThresholdMax () const;
159 
160  /** \brief Set an image, that will be used for coloring of the output cloud.
161  * \param[in] image the image.
162  */
163  void
165 
166  /** \brief Get the image, that is used for coloring of the output cloud.
167  * \return the image.
168  */
170  getImage ();
171 
172  /** \brief Load the disparity map.
173  * \param[in] file_name the name of the disparity map file.
174  * \return "true" if the disparity map was successfully loaded; "false" otherwise
175  */
176  bool
177  loadDisparityMap (const std::string &file_name);
178 
179  /** \brief Load the disparity map and initialize it's size.
180  * \param[in] file_name the name of the disparity map file.
181  * \param[in] width width of the disparity map.
182  * \param[in] height height of the disparity map.
183  * \return "true" if the disparity map was successfully loaded; "false" otherwise
184  */
185  bool
186  loadDisparityMap (const std::string &file_name, const size_t width, const size_t height);
187 
188  /** \brief Set the disparity map.
189  * \param[in] disparity_map the disparity map.
190  */
191  void
192  setDisparityMap (const std::vector<float> &disparity_map);
193 
194  /** \brief Set the disparity map and initialize it's size.
195  * \param[in] disparity_map the disparity map.
196  * \param[in] width width of the disparity map.
197  * \param[in] height height of the disparity map.
198  * \return "true" if the disparity map was successfully loaded; "false" otherwise
199  */
200  void
201  setDisparityMap (const std::vector<float> &disparity_map,
202  const size_t width, const size_t height);
203 
204  /** \brief Get the disparity map.
205  * \return the disparity map.
206  */
207  std::vector<float>
208  getDisparityMap ();
209 
210  /** \brief Compute the output cloud.
211  * \param[out] out_cloud the variable to return the resulting cloud.
212  */
213  virtual void
214  compute (PointCloud &out_cloud);
215 
216  protected:
217  /** \brief Translate point from image coordinates and disparity to 3D-coordinates
218  * \param[in] row
219  * \param[in] column
220  * \param[in] disparity
221  * \return the 3D point, that corresponds to the input parametres and the camera calibration.
222  */
223  PointXYZ
224  translateCoordinates (size_t row, size_t column, float disparity) const;
225 
226  /** \brief X-coordinate of the image center. */
227  float center_x_;
228  /** \brief Y-coordinate of the image center. */
229  float center_y_;
230  /** \brief Focal length. */
232  /** \brief Baseline. */
233  float baseline_;
234 
235  /** \brief Is color image is set. */
236  bool is_color_;
237  /** \brief Color image of the scene. */
239 
240  /** \brief Vector for the disparity map. */
241  std::vector<float> disparity_map_;
242  /** \brief X-size of the disparity map. */
244  /** \brief Y-size of the disparity map. */
246 
247  /** \brief Thresholds of the disparity. */
250  };
251 
252 }
253 
254 #include <pcl/stereo/impl/disparity_map_converter.hpp>
255 
256 #endif // PCL_DISPARITY_MAP_CONVERTER_H_
pcl::PointCloud< PointT > PointCloud
bool is_color_
Is color image is set.
void setFocalLength(const float focal_length)
Set focal length.
float getImageCenterX() const
Get x-coordinate of the image center.
float getBaseline() const
Get baseline.
float getFocalLength() const
Get focal length.
bool loadDisparityMap(const std::string &file_name)
Load the disparity map.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
float getDisparityThresholdMin() const
Get min disparity threshold.
void setDisparityMap(const std::vector< float > &disparity_map)
Set the disparity map.
virtual void compute(PointCloud &out_cloud)
Compute the output cloud.
DisparityMapConverter()
DisparityMapConverter constructor.
std::vector< float > getDisparityMap()
Get the disparity map.
PointXYZ translateCoordinates(size_t row, size_t column, float disparity) const
Translate point from image coordinates and disparity to 3D-coordinates.
void setDisparityThresholdMax(const float disparity_threshold_max)
Set max disparity threshold.
pcl::PointCloud< pcl::RGB >::ConstPtr image_
Color image of the scene.
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
virtual ~DisparityMapConverter()
Empty destructor.
size_t disparity_map_width_
X-size of the disparity map.
Defines all the PCL implemented PointT point type structures.
void setDisparityThresholdMin(const float disparity_threshold_min)
Set min disparity threshold.
A point structure representing Euclidean xyz coordinates.
Compute point cloud from the disparity map.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
float getImageCenterY() const
Get y-coordinate of the image center.
float getDisparityThresholdMax() const
Get max disparity threshold.
PointCloud represents the base class in PCL for storing collections of 3D points.
float center_x_
X-coordinate of the image center.
void setBaseline(const float baseline)
Set baseline.
void setImageCenterY(const float center_y)
Set y-coordinate of the image center.
void setImage(const pcl::PointCloud< pcl::RGB >::ConstPtr &image)
Set an image, that will be used for coloring of the output cloud.
void setImageCenterX(const float center_x)
Set x-coordinate of the image center.
std::vector< float > disparity_map_
Vector for the disparity map.
size_t disparity_map_height_
Y-size of the disparity map.
float disparity_threshold_min_
Thresholds of the disparity.
pcl::PointCloud< RGB >::Ptr getImage()
Get the image, that is used for coloring of the output cloud.
float center_y_
Y-coordinate of the image center.