7 #ifndef IMAGE_PROC_UTILS_H
8 #define IMAGE_PROC_UTILS_H
13 #include <opencv2/calib3d.hpp>
65 cv::Mat K_raw = cv::Mat(3, 3, CV_64F, k_raw_array);
66 cv::Mat D_raw = cv::Mat(1, 8, CV_64F, d_raw_array);
68 cv::Mat K_rect = cv::getOptimalNewCameraMatrix(K_raw, D_raw, img_size, 0, img_size,
nullptr);
71 cv::Mat r = cv::Mat::eye(3, 3, CV_32F);
79 cv::Mat distorted_pt(1, 1, CV_32FC2, cv::Scalar(x, y));
80 cv::Mat undistorted_pt(1, 1, CV_32FC2);
82 cv::undistortPoints(distorted_pt, undistorted_pt, K_raw, D_raw);
84 float ux = undistorted_pt.at<
float>(0);
85 float uy = undistorted_pt.at<
float>(1);
87 float scale_factor = 1.0f / sqrtf(1.0f + ux * ux + uy * uy);
89 *range_to_3d_lut++ = (ux * scale_factor);
90 *range_to_3d_lut++ = (uy * scale_factor);
91 *range_to_3d_lut++ = (scale_factor);
113 unsigned short depth = (*range_image);
116 *xyz_frame++ = (*range_to_3d_lut++) * (depth);
117 *xyz_frame++ = (*range_to_3d_lut++) * (depth);
118 *xyz_frame++ = (*range_to_3d_lut++) * (depth);
130 static void gammaCorrect(
unsigned short* src_dst,
int num_pixels)
132 for (
int i = 0; i < num_pixels; i++)
134 float pixel_value = (float)src_dst[i];
135 float out_pixel_value = (float)(255.0f * log(pixel_value)) / log(2048.0f);
136 src_dst[i] = (
unsigned short)out_pixel_value;