Loading...
Searching...
No Matches
disparity_map_converter.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <cstring>
#include <vector>
namespace pcl {
/** \brief Compute point cloud from the disparity map.
*
* Example of usage:
*
* \code
* pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new
* pcl::PointCloud<pcl::PointXYZI>);
* pcl::PointCloud<pcl::RGB>::Ptr left_image (new
* pcl::PointCloud<pcl::RGB>);
* // Fill left image cloud.
*
* pcl::DisparityMapConverter<pcl::PointXYZI> dmc;
* dmc.setBaseline (0.8387445f);
* dmc.setFocalLength (368.534700f);
* dmc.setImageCenterX (318.112200f);
* dmc.setImageCenterY (224.334900f);
* dmc.setDisparityThresholdMin(15.0f);
*
* // Left view of the scene.
* dmc.setImage (left_image);
* // Disparity map of the scene.
* dmc.loadDisparityMap ("disparity_map.txt", 640, 480);
*
* dmc.compute(*cloud);
* \endcode
*
* \author Timur Ibadov (ibadov.timur@gmail.com)
* \ingroup stereo
*/
template <typename PointT>
class DisparityMapConverter {
protected:
using PointCloud = pcl::PointCloud<PointT>;
public:
/** \brief DisparityMapConverter constructor. */
DisparityMapConverter();
/** \brief Empty destructor. */
virtual ~DisparityMapConverter();
/** \brief Set x-coordinate of the image center.
* \param[in] center_x x-coordinate of the image center.
*/
inline void
setImageCenterX(const float center_x);
/** \brief Get x-coordinate of the image center.
* \return x-coordinate of the image center.
*/
inline float
getImageCenterX() const;
/** \brief Set y-coordinate of the image center.
* \param[in] center_y y-coordinate of the image center.
*/
inline void
setImageCenterY(const float center_y);
/** \brief Get y-coordinate of the image center.
* \return y-coordinate of the image center.
*/
inline float
getImageCenterY() const;
/** \brief Set focal length.
* \param[in] focal_length the focal length.
*/
inline void
setFocalLength(const float focal_length);
/** \brief Get focal length.
* \return the focal length.
*/
inline float
getFocalLength() const;
/** \brief Set baseline.
* \param[in] baseline baseline.
*/
inline void
setBaseline(const float baseline);
/** \brief Get baseline.
* \return the baseline.
*/
inline float
getBaseline() const;
/** \brief Set min disparity threshold.
* \param[in] disparity_threshold_min min disparity threshold.
*/
inline void
setDisparityThresholdMin(const float disparity_threshold_min);
/** \brief Get min disparity threshold.
* \return min disparity threshold.
*/
inline float
getDisparityThresholdMin() const;
/** \brief Set max disparity threshold.
* \param[in] disparity_threshold_max max disparity threshold.
*/
inline void
setDisparityThresholdMax(const float disparity_threshold_max);
/** \brief Get max disparity threshold.
* \return max disparity threshold.
*/
inline float
getDisparityThresholdMax() const;
/** \brief Set an image, that will be used for coloring of the output cloud.
* \param[in] image the image.
*/
void
setImage(const pcl::PointCloud<pcl::RGB>::ConstPtr& image);
/** \brief Get the image, that is used for coloring of the output cloud.
* \return the image.
*/
pcl::PointCloud<RGB>::Ptr
getImage();
/** \brief Load the disparity map.
* \param[in] file_name the name of the disparity map file.
* \return "true" if the disparity map was successfully loaded; "false" otherwise
*/
bool
loadDisparityMap(const std::string& file_name);
/** \brief Load the disparity map and initialize it's size.
* \param[in] file_name the name of the disparity map file.
* \param[in] width width of the disparity map.
* \param[in] height height of the disparity map.
* \return "true" if the disparity map was successfully loaded; "false" otherwise
*/
bool
loadDisparityMap(const std::string& file_name,
const std::size_t width,
const std::size_t height);
/** \brief Set the disparity map.
* \param[in] disparity_map the disparity map.
*/
void
setDisparityMap(const std::vector<float>& disparity_map);
/** \brief Set the disparity map and initialize it's size.
* \param[in] disparity_map the disparity map.
* \param[in] width width of the disparity map.
* \param[in] height height of the disparity map.
* \return "true" if the disparity map was successfully loaded; "false" otherwise
*/
void
setDisparityMap(const std::vector<float>& disparity_map,
const std::size_t width,
const std::size_t height);
/** \brief Get the disparity map.
* \return the disparity map.
*/
std::vector<float>
getDisparityMap();
/** \brief Compute the output cloud.
* \param[out] out_cloud the variable to return the resulting cloud.
*/
virtual void
compute(PointCloud& out_cloud);
protected:
/** \brief Translate point from image coordinates and disparity to 3D-coordinates
* \param[in] row
* \param[in] column
* \param[in] disparity
* \return the 3D point, that corresponds to the input parameters and the camera
* calibration.
*/
PointXYZ
translateCoordinates(std::size_t row, std::size_t column, float disparity) const;
/** \brief X-coordinate of the image center. */
float center_x_{0.0f};
/** \brief Y-coordinate of the image center. */
float center_y_{0.0f};
/** \brief Focal length. */
float focal_length_{0.0f};
/** \brief Baseline. */
float baseline_{0.0f};
/** \brief Is color image is set. */
bool is_color_{false};
/** \brief Color image of the scene. */
pcl::PointCloud<pcl::RGB>::ConstPtr image_;
/** \brief Vector for the disparity map. */
std::vector<float> disparity_map_;
/** \brief X-size of the disparity map. */
std::size_t disparity_map_width_{640};
/** \brief Y-size of the disparity map. */
std::size_t disparity_map_height_{480};
/** \brief Thresholds of the disparity. */
float disparity_threshold_min_{0.0f};
float disparity_threshold_max_;
};
} // namespace pcl
#include <pcl/stereo/impl/disparity_map_converter.hpp>
pcl::DisparityMapConverter
Compute point cloud from the disparity map.
Definition disparity_map_converter.h:77
pcl::DisparityMapConverter::disparity_map_
std::vector< float > disparity_map_
Vector for the disparity map.
Definition disparity_map_converter.h:245
pcl::DisparityMapConverter::getBaseline
float getBaseline() const
Get baseline.
Definition disparity_map_converter.hpp:107
pcl::DisparityMapConverter::focal_length_
float focal_length_
Focal length.
Definition disparity_map_converter.h:235
pcl::DisparityMapConverter::getDisparityMap
std::vector< float > getDisparityMap()
Get the disparity map.
Definition disparity_map_converter.hpp:231
pcl::DisparityMapConverter::image_
pcl::PointCloud< pcl::RGB >::ConstPtr image_
Color image of the scene.
Definition disparity_map_converter.h:242
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:79
pcl::DisparityMapConverter::setDisparityThresholdMax
void setDisparityThresholdMax(const float disparity_threshold_max)
Set max disparity threshold.
Definition disparity_map_converter.hpp:129
pcl::DisparityMapConverter::getImageCenterX
float getImageCenterX() const
Get x-coordinate of the image center.
Definition disparity_map_converter.hpp:65
pcl::DisparityMapConverter::baseline_
float baseline_
Baseline.
Definition disparity_map_converter.h:237
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:144
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:295
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:158
pcl::DisparityMapConverter::compute
virtual void compute(PointCloud &out_cloud)
Compute the output cloud.
Definition disparity_map_converter.hpp:238
pcl::DisparityMapConverter::loadDisparityMap
bool loadDisparityMap(const std::string &file_name)
Load the disparity map.
Definition disparity_map_converter.hpp:167
pcl::DisparityMapConverter::setImageCenterX
void setImageCenterX(const float center_x)
Set x-coordinate of the image center.
Definition disparity_map_converter.hpp:58
pcl::DisparityMapConverter::~DisparityMapConverter
virtual ~DisparityMapConverter()
Empty destructor.
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::center_y_
float center_y_
Y-coordinate of the image center.
Definition disparity_map_converter.h:233
pcl::DisparityMapConverter::setDisparityMap
void setDisparityMap(const std::vector< float > &disparity_map)
Set the disparity map.
Definition disparity_map_converter.hpp:210
pcl::DisparityMapConverter::is_color_
bool is_color_
Is color image is set.
Definition disparity_map_converter.h:240
pcl::DisparityMapConverter::setDisparityThresholdMin
void setDisparityThresholdMin(const float disparity_threshold_min)
Set min disparity threshold.
Definition disparity_map_converter.hpp:114
pcl::DisparityMapConverter::getDisparityThresholdMax
float getDisparityThresholdMax() const
Get max disparity threshold.
Definition disparity_map_converter.hpp:137
pcl::DisparityMapConverter::getDisparityThresholdMin
float getDisparityThresholdMin() const
Get min disparity threshold.
Definition disparity_map_converter.hpp:122
pcl::DisparityMapConverter::setBaseline
void setBaseline(const float baseline)
Set baseline.
Definition disparity_map_converter.hpp:100
pcl::DisparityMapConverter::getFocalLength
float getFocalLength() const
Get focal length.
Definition disparity_map_converter.hpp:93
pcl::DisparityMapConverter::setFocalLength
void setFocalLength(const float focal_length)
Set focal length.
Definition disparity_map_converter.hpp:86
pcl::DisparityMapConverter::center_x_
float center_x_
X-coordinate of the image center.
Definition disparity_map_converter.h:231
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::disparity_threshold_min_
float disparity_threshold_min_
Thresholds of the disparity.
Definition disparity_map_converter.h:252
pcl::DisparityMapConverter::setImageCenterY
void setImageCenterY(const float center_y)
Set y-coordinate of the image center.
Definition disparity_map_converter.hpp:72
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition point_cloud.h:414
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl
Definition convolution.h:46
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition point_types.hpp:322