Point Cloud Library (PCL)  1.11.0
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. */
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,
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 parametres 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_;
232  /** \brief Y-coordinate of the image center. */
233  float center_y_;
234  /** \brief Focal length. */
236  /** \brief Baseline. */
237  float baseline_;
238 
239  /** \brief Is color image is set. */
240  bool is_color_;
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_;
248  /** \brief Y-size of the disparity map. */
250 
251  /** \brief Thresholds of the disparity. */
254 };
255 
256 } // namespace pcl
257 
258 #include <pcl/stereo/impl/disparity_map_converter.hpp>
pcl
Definition: convolution.h:46
point_types.h
pcl::DisparityMapConverter::setFocalLength
void setFocalLength(const float focal_length)
Set focal length.
Definition: disparity_map_converter.hpp:95
pcl::DisparityMapConverter
Compute point cloud from the disparity map.
Definition: disparity_map_converter.h:77
pcl::DisparityMapConverter::getFocalLength
float getFocalLength() const
Get focal length.
Definition: disparity_map_converter.hpp:102
pcl::DisparityMapConverter::disparity_threshold_min_
float disparity_threshold_min_
Thresholds of the disparity.
Definition: disparity_map_converter.h:252
pcl::DisparityMapConverter::setDisparityMap
void setDisparityMap(const std::vector< float > &disparity_map)
Set the disparity map.
Definition: disparity_map_converter.hpp:219
pcl::DisparityMapConverter::DisparityMapConverter
DisparityMapConverter()
DisparityMapConverter constructor.
Definition: disparity_map_converter.hpp:49
pcl::DisparityMapConverter::disparity_map_height_
std::size_t disparity_map_height_
Y-size of the disparity map.
Definition: disparity_map_converter.h:249
pcl::DisparityMapConverter::getDisparityMap
std::vector< float > getDisparityMap()
Get the disparity map.
Definition: disparity_map_converter.hpp:240
pcl::DisparityMapConverter::is_color_
bool is_color_
Is color image is set.
Definition: disparity_map_converter.h:240
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:52
pcl::DisparityMapConverter::center_x_
float center_x_
X-coordinate of the image center.
Definition: disparity_map_converter.h:231
pcl::DisparityMapConverter::getBaseline
float getBaseline() const
Get baseline.
Definition: disparity_map_converter.hpp:116
pcl::DisparityMapConverter::getDisparityThresholdMin
float getDisparityThresholdMin() const
Get min disparity threshold.
Definition: disparity_map_converter.hpp:131
pcl::DisparityMapConverter::center_y_
float center_y_
Y-coordinate of the image center.
Definition: disparity_map_converter.h:233
pcl::DisparityMapConverter::disparity_threshold_max_
float disparity_threshold_max_
Definition: disparity_map_converter.h:253
pcl::DisparityMapConverter::getImageCenterY
float getImageCenterY() const
Get y-coordinate of the image center.
Definition: disparity_map_converter.hpp:88
pcl::DisparityMapConverter::disparity_map_width_
std::size_t disparity_map_width_
X-size of the disparity map.
Definition: disparity_map_converter.h:247
pcl::DisparityMapConverter::setImage
void setImage(const pcl::PointCloud< pcl::RGB >::ConstPtr &image)
Set an image, that will be used for coloring of the output cloud.
Definition: disparity_map_converter.hpp:153
pcl::DisparityMapConverter::setImageCenterX
void setImageCenterX(const float center_x)
Set x-coordinate of the image center.
Definition: disparity_map_converter.hpp:67
pcl::DisparityMapConverter::disparity_map_
std::vector< float > disparity_map_
Vector for the disparity map.
Definition: disparity_map_converter.h:245
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:301
pcl::DisparityMapConverter::loadDisparityMap
bool loadDisparityMap(const std::string &file_name)
Load the disparity map.
Definition: disparity_map_converter.hpp:176
pcl::DisparityMapConverter::image_
pcl::PointCloud< pcl::RGB >::ConstPtr image_
Color image of the scene.
Definition: disparity_map_converter.h:242
pcl::DisparityMapConverter::getDisparityThresholdMax
float getDisparityThresholdMax() const
Get max disparity threshold.
Definition: disparity_map_converter.hpp:146
pcl::DisparityMapConverter::getImage
pcl::PointCloud< RGB >::Ptr getImage()
Get the image, that is used for coloring of the output cloud.
Definition: disparity_map_converter.hpp:167
pcl::DisparityMapConverter::~DisparityMapConverter
virtual ~DisparityMapConverter()
Empty destructor.
Definition: disparity_map_converter.hpp:62
pcl::DisparityMapConverter::setImageCenterY
void setImageCenterY(const float center_y)
Set y-coordinate of the image center.
Definition: disparity_map_converter.hpp:81
pcl::DisparityMapConverter::baseline_
float baseline_
Baseline.
Definition: disparity_map_converter.h:237
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::DisparityMapConverter::getImageCenterX
float getImageCenterX() const
Get x-coordinate of the image center.
Definition: disparity_map_converter.hpp:74
pcl::DisparityMapConverter::setDisparityThresholdMax
void setDisparityThresholdMax(const float disparity_threshold_max)
Set max disparity threshold.
Definition: disparity_map_converter.hpp:138
pcl::DisparityMapConverter::focal_length_
float focal_length_
Focal length.
Definition: disparity_map_converter.h:235
pcl::DisparityMapConverter::setBaseline
void setBaseline(const float baseline)
Set baseline.
Definition: disparity_map_converter.hpp:109
pcl::DisparityMapConverter::compute
virtual void compute(PointCloud &out_cloud)
Compute the output cloud.
Definition: disparity_map_converter.hpp:247
pcl::DisparityMapConverter::setDisparityThresholdMin
void setDisparityThresholdMin(const float disparity_threshold_min)
Set min disparity threshold.
Definition: disparity_map_converter.hpp:123
pcl::DisparityMapConverter::translateCoordinates
PointXYZ translateCoordinates(std::size_t row, std::size_t column, float disparity) const
Translate point from image coordinates and disparity to 3D-coordinates.
Definition: disparity_map_converter.hpp:304