Point Cloud Library (PCL)  1.14.1-dev
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 
37 #pragma once
38 
39 #include <pcl/point_cloud.h>
40 #include <pcl/point_types.h>
41 
42 #include <cstring>
43 #include <vector>
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 protected:
80 
81 public:
82  /** \brief DisparityMapConverter constructor. */
84 
85  /** \brief Empty destructor. */
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,
187  const std::size_t width,
188  const std::size_t height);
189 
190  /** \brief Set the disparity map.
191  * \param[in] disparity_map the disparity map.
192  */
193  void
194  setDisparityMap(const std::vector<float>& disparity_map);
195 
196  /** \brief Set the disparity map and initialize it's size.
197  * \param[in] disparity_map the disparity map.
198  * \param[in] width width of the disparity map.
199  * \param[in] height height of the disparity map.
200  * \return "true" if the disparity map was successfully loaded; "false" otherwise
201  */
202  void
203  setDisparityMap(const std::vector<float>& disparity_map,
204  const std::size_t width,
205  const std::size_t height);
206 
207  /** \brief Get the disparity map.
208  * \return the disparity map.
209  */
210  std::vector<float>
211  getDisparityMap();
212 
213  /** \brief Compute the output cloud.
214  * \param[out] out_cloud the variable to return the resulting cloud.
215  */
216  virtual void
217  compute(PointCloud& out_cloud);
218 
219 protected:
220  /** \brief Translate point from image coordinates and disparity to 3D-coordinates
221  * \param[in] row
222  * \param[in] column
223  * \param[in] disparity
224  * \return the 3D point, that corresponds to the input parameters and the camera
225  * calibration.
226  */
227  PointXYZ
228  translateCoordinates(std::size_t row, std::size_t column, float disparity) const;
229 
230  /** \brief X-coordinate of the image center. */
231  float center_x_{0.0f};
232  /** \brief Y-coordinate of the image center. */
233  float center_y_{0.0f};
234  /** \brief Focal length. */
235  float focal_length_{0.0f};
236  /** \brief Baseline. */
237  float baseline_{0.0f};
238 
239  /** \brief Is color image is set. */
240  bool is_color_{false};
241  /** \brief Color image of the scene. */
243 
244  /** \brief Vector for the disparity map. */
245  std::vector<float> disparity_map_;
246  /** \brief X-size of the disparity map. */
247  std::size_t disparity_map_width_{640};
248  /** \brief Y-size of the disparity map. */
249  std::size_t disparity_map_height_{480};
250 
251  /** \brief Thresholds of the disparity. */
254 };
255 
256 } // namespace pcl
257 
258 #include <pcl/stereo/impl/disparity_map_converter.hpp>
Compute point cloud from the disparity map.
std::vector< float > disparity_map_
Vector for the disparity map.
float getBaseline() const
Get baseline.
std::vector< float > getDisparityMap()
Get the disparity map.
pcl::PointCloud< pcl::RGB >::ConstPtr image_
Color image of the scene.
float getImageCenterY() const
Get y-coordinate of the image center.
void setDisparityThresholdMax(const float disparity_threshold_max)
Set max disparity threshold.
float getImageCenterX() const
Get x-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.
PointXYZ translateCoordinates(std::size_t row, std::size_t column, float disparity) const
Translate point from image coordinates and disparity to 3D-coordinates.
pcl::PointCloud< RGB >::Ptr getImage()
Get the image, that is used for coloring of the output cloud.
virtual void compute(PointCloud &out_cloud)
Compute the output cloud.
bool loadDisparityMap(const std::string &file_name)
Load the disparity map.
void setImageCenterX(const float center_x)
Set x-coordinate of the image center.
virtual ~DisparityMapConverter()
Empty destructor.
DisparityMapConverter()
DisparityMapConverter constructor.
std::size_t disparity_map_height_
Y-size of the disparity map.
float center_y_
Y-coordinate of the image center.
void setDisparityMap(const std::vector< float > &disparity_map)
Set the disparity map.
bool is_color_
Is color image is set.
void setDisparityThresholdMin(const float disparity_threshold_min)
Set min disparity threshold.
float getDisparityThresholdMax() const
Get max disparity threshold.
float getDisparityThresholdMin() const
Get min disparity threshold.
void setBaseline(const float baseline)
Set baseline.
float getFocalLength() const
Get focal length.
void setFocalLength(const float focal_length)
Set focal length.
float center_x_
X-coordinate of the image center.
std::size_t disparity_map_width_
X-size of the disparity map.
float disparity_threshold_min_
Thresholds of the disparity.
void setImageCenterY(const float center_y)
Set y-coordinate of the image center.
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
Defines all the PCL implemented PointT point type structures.
A point structure representing Euclidean xyz coordinates.