Guest User

depth.h

a guest
Mar 25th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.74 KB | None | 0 0
  1. #ifndef DEPTH_H
  2. #define DEPTH_H
  3.  
  4. #include <opencv2/opencv.hpp>
  5. #include <pcl/point_cloud.h>
  6. #include <pcl/point_types.h>
  7. #include <pcl/features/normal_3d.h>
  8. #include <pcl/features/integral_image_normal.h>
  9.  
  10.     namespace tools {
  11.  
  12.         /**
  13.          * Struct representing basic intrinsic parameters used to
  14.          * compute a point cloud from a depth image.
  15.          */
  16.         struct Camera {
  17.  
  18.             /**
  19.              * Default constructor.
  20.              */
  21.             Camera();
  22.            
  23.             /**
  24.              * Constructor.
  25.              *
  26.              * @param principalPointX
  27.              * @param principalPointY
  28.              * @param focalLenghtX
  29.              * @param focalLengthY
  30.              */
  31.             Camera(float principalPointX, float principalPointY, float focalLenghtX, float focalLengthY);
  32.            
  33.             /**
  34.              * Get the z coordinate of the projected point given the depth as
  35.              * depth/factor.
  36.              *
  37.              * @param depth
  38.              * @param factor
  39.              * @return
  40.              */
  41.             float projectZ(unsigned short depth, float factor = 1000.);
  42.            
  43.             /**
  44.              * Given the depth by depth/factor, project the x coordinate into
  45.              * 3D room.
  46.              *
  47.              * @param x
  48.              * @param depth
  49.              * @param factor
  50.              * @return
  51.              */
  52.             template <typename T>
  53.             float projectX(T x, unsigned short depth, float factor = 1000.);
  54.            
  55.             /**
  56.              * Given the depth by depth/factor, project the y coordinate into
  57.              * 3D room.
  58.              *
  59.              * @param y
  60.              * @param depth
  61.              * @param factor
  62.              * @return
  63.              */
  64.             template <typename T>
  65.             float projectY(T y, unsigned short depth, float factor = 1000.);
  66.            
  67.             /**
  68.              * Given the depth by depth/factor, unproject the x coordinate to
  69.              * image plain.
  70.              *
  71.              * @param x
  72.              * @param depth
  73.              * @return
  74.              */
  75.             int unprojectX(float x, float depth);
  76.            
  77.             /**
  78.              * Given the depth by depth/factor, unproject the y coordinate to
  79.              * image plain.
  80.              *
  81.              * @param y
  82.              * @param depth
  83.              * @return
  84.              */
  85.             int unprojectY(float y, float depth);
  86.            
  87.             float principalPointX;
  88.             float principalPointY;
  89.             float focalLengthX;
  90.             float focalLengthY;
  91.         };
  92.  
  93.         /**
  94.          * Class Depth can be used to handle depth data of any kinds. The class
  95.          * provides methods for converting depth images to point clouds.
  96.          */
  97.         class Depth {
  98.  
  99.         public:
  100.  
  101.             /**
  102.              * Given a depth map and the intrinsic parameters of the camera,
  103.              * this method computes a point cloud from using the Point Cloud
  104.              * Library.
  105.              *
  106.              * The depth image is assumed to contain the depth in millimeters as
  107.              * unsigned integers (so no better accuracy than millimeters).
  108.              *
  109.              * @param depth
  110.              * @param camera
  111.              * @param factor
  112.              * @return
  113.              */
  114.             static pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloudFromDepth(const cv::Mat &depth, Camera camera, float factor = 1000.);
  115.  
  116.             /**
  117.              * Fiven a depth map and an image, this methods creates a pint cloud
  118.              * containing XYZRGB points.
  119.              *
  120.              * The depth image is assumed to contain the depth in millimeters as
  121.              * unsigned integers (so no better accuracy than millimeters).
  122.              *
  123.              * Input image is expected to have BGR color space.
  124.              *
  125.              * @param iamge
  126.              * @param depth
  127.              * @param camera
  128.              * @param factor
  129.              * @return
  130.              */
  131.             static pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pointCloudFromBGRAndDepth(const cv::Mat &image, const cv::Mat &depth, Camera camera, float factor = 1000.);
  132.            
  133.             /**
  134.              * Given a depth map and the intrinsic parameters, this function
  135.              * comptued an unordered point cloud where each pixel with depth == 0
  136.              * is ignored.
  137.              *
  138.              * For color information the given image is assumed to ahve BGR color space.
  139.              *
  140.              * @param iamge
  141.              * @param depth
  142.              * @param camera
  143.              * @param factor
  144.              * @return
  145.              */
  146.             static pcl::PointCloud<pcl::PointXYZRGBA>::Ptr unorderedPointCloudFromBGRAndDepth(const cv::Mat &image, const cv::Mat &depth, Camera camera, float factor = 1000.);
  147.            
  148.             /**
  149.              * Draw an image where the normals are colored, simply by
  150.              * normalizing them and multiplying by 255 in each component.
  151.              *
  152.              * @param pointCloud
  153.              * @param bgr
  154.              */
  155.             template <typename T>
  156.             static cv::Mat drawNormalImage(typename pcl::PointCloud<T>::Ptr pointCloud, int* bgr);
  157.            
  158.             /**
  159.              * Draw an image where each pixel is colored according to the normal of
  160.              * its superpixel.
  161.              *
  162.              * @param pointCloud
  163.              * @param labels
  164.              */
  165.             template <typename T>
  166.             static cv::Mat drawNormalSegments(typename pcl::PointCloud<T>::Ptr pointCloud, int** labels);
  167.         };
  168.     }
  169.  
  170. #endif    /* DEPTH_H */
Add Comment
Please, Sign In to add comment