Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DEPTH_H
- #define DEPTH_H
- #include <opencv2/opencv.hpp>
- #include <pcl/point_cloud.h>
- #include <pcl/point_types.h>
- #include <pcl/features/normal_3d.h>
- #include <pcl/features/integral_image_normal.h>
- namespace tools {
- /**
- * Struct representing basic intrinsic parameters used to
- * compute a point cloud from a depth image.
- */
- struct Camera {
- /**
- * Default constructor.
- */
- Camera();
- /**
- * Constructor.
- *
- * @param principalPointX
- * @param principalPointY
- * @param focalLenghtX
- * @param focalLengthY
- */
- Camera(float principalPointX, float principalPointY, float focalLenghtX, float focalLengthY);
- /**
- * Get the z coordinate of the projected point given the depth as
- * depth/factor.
- *
- * @param depth
- * @param factor
- * @return
- */
- float projectZ(unsigned short depth, float factor = 1000.);
- /**
- * Given the depth by depth/factor, project the x coordinate into
- * 3D room.
- *
- * @param x
- * @param depth
- * @param factor
- * @return
- */
- template <typename T>
- float projectX(T x, unsigned short depth, float factor = 1000.);
- /**
- * Given the depth by depth/factor, project the y coordinate into
- * 3D room.
- *
- * @param y
- * @param depth
- * @param factor
- * @return
- */
- template <typename T>
- float projectY(T y, unsigned short depth, float factor = 1000.);
- /**
- * Given the depth by depth/factor, unproject the x coordinate to
- * image plain.
- *
- * @param x
- * @param depth
- * @return
- */
- int unprojectX(float x, float depth);
- /**
- * Given the depth by depth/factor, unproject the y coordinate to
- * image plain.
- *
- * @param y
- * @param depth
- * @return
- */
- int unprojectY(float y, float depth);
- float principalPointX;
- float principalPointY;
- float focalLengthX;
- float focalLengthY;
- };
- /**
- * Class Depth can be used to handle depth data of any kinds. The class
- * provides methods for converting depth images to point clouds.
- */
- class Depth {
- public:
- /**
- * Given a depth map and the intrinsic parameters of the camera,
- * this method computes a point cloud from using the Point Cloud
- * Library.
- *
- * The depth image is assumed to contain the depth in millimeters as
- * unsigned integers (so no better accuracy than millimeters).
- *
- * @param depth
- * @param camera
- * @param factor
- * @return
- */
- static pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloudFromDepth(const cv::Mat &depth, Camera camera, float factor = 1000.);
- /**
- * Fiven a depth map and an image, this methods creates a pint cloud
- * containing XYZRGB points.
- *
- * The depth image is assumed to contain the depth in millimeters as
- * unsigned integers (so no better accuracy than millimeters).
- *
- * Input image is expected to have BGR color space.
- *
- * @param iamge
- * @param depth
- * @param camera
- * @param factor
- * @return
- */
- static pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pointCloudFromBGRAndDepth(const cv::Mat &image, const cv::Mat &depth, Camera camera, float factor = 1000.);
- /**
- * Given a depth map and the intrinsic parameters, this function
- * comptued an unordered point cloud where each pixel with depth == 0
- * is ignored.
- *
- * For color information the given image is assumed to ahve BGR color space.
- *
- * @param iamge
- * @param depth
- * @param camera
- * @param factor
- * @return
- */
- static pcl::PointCloud<pcl::PointXYZRGBA>::Ptr unorderedPointCloudFromBGRAndDepth(const cv::Mat &image, const cv::Mat &depth, Camera camera, float factor = 1000.);
- /**
- * Draw an image where the normals are colored, simply by
- * normalizing them and multiplying by 255 in each component.
- *
- * @param pointCloud
- * @param bgr
- */
- template <typename T>
- static cv::Mat drawNormalImage(typename pcl::PointCloud<T>::Ptr pointCloud, int* bgr);
- /**
- * Draw an image where each pixel is colored according to the normal of
- * its superpixel.
- *
- * @param pointCloud
- * @param labels
- */
- template <typename T>
- static cv::Mat drawNormalSegments(typename pcl::PointCloud<T>::Ptr pointCloud, int** labels);
- };
- }
- #endif /* DEPTH_H */
Add Comment
Please, Sign In to add comment