1 #include "header/depthCameraSupport.h" 11 void DCAM::rs_deproject_pixel_to_point(
float point[3],
const rs_intrinsics &intrin,
12 const float pixel[2],
float depth) {
14 float x = (pixel[0] - intrin.ppx) / intrin.fx;
15 float y = (pixel[1] - intrin.ppy) / intrin.fy;
16 float r2 = x * x + y * y;
17 float f = 1 + intrin.coeffs[0] * r2 + intrin.coeffs[1] * r2 * r2 + intrin.coeffs[4] * r2 * r2 * r2;
18 float ux = x * f + 2 * intrin.coeffs[2] * x * y + intrin.coeffs[3] * (r2 + 2 * x * x);
19 float uy = y * f + 2 * intrin.coeffs[3] * x * y + intrin.coeffs[2] * (r2 + 2 * y * y);
28 bool DCAM::makePointCloud(vpImage<uint16_t> &I_depth_raw,
29 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud){
31 unsigned int height = I_depth_raw.getRows();
32 unsigned int width = I_depth_raw.getCols();
35 pointcloud->width = width;
36 pointcloud->height = height;
37 pointcloud->reserve((
size_t)width * height);
39 const float depth_scale = 1.0f;
41 depth_intrinsic.ppx = 120.0f;
42 depth_intrinsic.ppy = 160.0f;
43 depth_intrinsic.fx = 257.986f;
44 depth_intrinsic.fy = 257.341f;
45 depth_intrinsic.coeffs[0] = 0.0f;
46 depth_intrinsic.coeffs[1] = 0.0f;
47 depth_intrinsic.coeffs[2] = 0.0f;
48 depth_intrinsic.coeffs[3] = 0.0f;
49 depth_intrinsic.coeffs[4] = 0.0f;
50 for (
unsigned int i = 0; i < height; i++) {
51 for (
unsigned int j = 0; j < width; j++) {
52 float scaled_depth = I_depth_raw[i][j] * depth_scale;
54 float pixel[2] = {(float)j, (
float)i};
55 rs_deproject_pixel_to_point(point, depth_intrinsic, pixel, scaled_depth);
56 pointcloud->push_back(pcl::PointXYZ(point[0], point[1], point[2]));
63 bool DCAM::makePointCloud(cv::Mat I_depth_raw,
64 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud){
66 unsigned int height = I_depth_raw.rows;
67 unsigned int width = I_depth_raw.cols;
70 pointcloud->width = width;
71 pointcloud->height = height;
72 pointcloud->reserve((
size_t)width * height);
74 const float depth_scale = 1.0f;
80 depth_intrinsic.ppx = 160.0f;
81 depth_intrinsic.ppy = 120.0f;
82 depth_intrinsic.fx = 257.34082279179285f;
83 depth_intrinsic.fy = 257.34083046114705f;
84 depth_intrinsic.coeffs[0] = 0.0f;
85 depth_intrinsic.coeffs[1] = 0.0f;
86 depth_intrinsic.coeffs[2] = 0.0f;
87 depth_intrinsic.coeffs[3] = 0.0f;
88 depth_intrinsic.coeffs[4] = 0.0f;
89 for (
unsigned int i = 0; i < height; i++) {
90 for (
unsigned int j = 0; j < width; j++) {
91 float scaled_depth = I_depth_raw.at<
float>(i,j) * depth_scale;
93 float pixel[2] = {(float)j, (
float)i};
94 rs_deproject_pixel_to_point(point, depth_intrinsic, pixel, scaled_depth);
95 pointcloud->push_back(pcl::PointXYZ(point[0], point[1], point[2]));