5 #include <Image/ByteImage.h>
9 #include <VisionX/interface/components/Calibration.h>
20 int imageSize = output->width * output->height * output->bytesPerPixel;
23 std::memcpy(output->pixels,
input.data, imageSize);
35 uchar* outRow = output->pixels;
36 int outStride = 3 * output->width;
39 cv::minMaxLoc(inputInMeters, &minD, &maxD);
41 float invRangeD = 1.0 / (maxD - minD);
43 for (
int y = 0; y < inputInMeters.rows; ++y)
45 float const* depthRow = inputInMeters.ptr<
float>(y);
46 for (
int x = 0; x < inputInMeters.cols; ++x)
48 float depth = depthRow[x];
49 float normalizedDepth = (depth - minD) * invRangeD;
50 int pixelValue = std::floor(255.0f - 255.0f * normalizedDepth);
52 outRow[3 * x + 0] = pixelValue;
53 outRow[3 * x + 1] = pixelValue;
54 outRow[3 * x + 2] = pixelValue;
66 int width =
input->width;
67 int height =
input->height;
68 cv::Mat result(height, width, CV_32FC1);
80 const unsigned char* inputRow =
input;
81 for (
int row = 0; row < output.rows; ++row)
83 float* outputRow = output.ptr<
float>(row);
84 for (
int col = 0; col < output.cols; ++col)
87 int r = inputRow[col * 3 + 0];
88 int g = inputRow[col * 3 + 1];
89 int depthInMM = (g << 8) + r;
90 outputRow[col] =
static_cast<float>(depthInMM) / 1000.0f;
93 inputRow += output.cols * 3;
106 const auto height = output->height;
107 const auto width = output->width;
109 unsigned char* outputRow = output->pixels;
110 for (
int y = 0; y < height; ++y)
112 const float* inputRow =
input.ptr<
float>(y);
113 for (
int x = 0; x < width; ++x)
115 const auto depthInMM = inputRow[x] * 1000;
117 outputRow[x * 3 + 0] =
static_cast<unsigned char>(std::fmod(depthInMM, 256));
118 outputRow[x * 3 + 1] =
static_cast<unsigned char>(std::fmod(depthInMM / 256, 256));
119 outputRow[x * 3 + 2] =
static_cast<unsigned char>(std::fmod(depthInMM / 256 / 256, 256));
122 inputRow += width * 3;
129 template <
typename Float>
132 output.at<
Float>(0, 1) = 0;
133 output.at<
Float>(1, 0) = 0;
134 output.at<
Float>(2, 0) = 0;
135 output.at<
Float>(2, 1) = 0;
136 output.at<
Float>(2, 2) = 1;
141 if (!(matrix.depth() == CV_32F || matrix.depth() == CV_64F))
143 std::stringstream ss;
144 ss <<
"Passed " << semanticName <<
" must be floating point type, "
145 <<
"i.e. CV_32F (" << CV_32F <<
") or CV_64F (" << CV_64F <<
"), "
146 <<
"but its type was " << matrix.type() <<
".";
147 throw std::invalid_argument(ss.str());
158 template <
typename Float>
159 void fillCameraMatrix(
const CCalibration::CCameraParameters& ivtCameraParameters, cv::Mat& output)
163 fillEmptyValues<Float>(output);
165 output.at<
Float>(0, 0) =
Float(ivtCameraParameters.focalLength.x);
166 output.at<
Float>(0, 2) =
Float(ivtCameraParameters.principalPoint.x);
167 output.at<
Float>(1, 1) =
Float(ivtCameraParameters.focalLength.y);
168 output.at<
Float>(1, 2) =
Float(ivtCameraParameters.principalPoint.y);
171 template <
typename Float>
179 const float nodalPointX = cameraParams.principalPoint.at(0);
180 const float nodalPointY = cameraParams.principalPoint.at(1);
181 const float focalLengthX = cameraParams.focalLength.at(0);
182 const float focalLengthY = cameraParams.focalLength.at(1);
184 fillEmptyValues<Float>(output);
198 if (output.depth() == CV_32F)
200 detail::fillCameraMatrix<float>(cameraParams, output);
202 else if (output.depth() == CV_64F)
204 detail::fillCameraMatrix<double>(cameraParams, output);
210 const CCalibration::CCameraParameters& ivtCameraParameters, cv::Mat& output)
213 if (output.depth() == CV_32F)
215 detail::fillCameraMatrix<float>(ivtCameraParameters, output);
217 else if (output.depth() == CV_64F)
219 detail::fillCameraMatrix<double>(ivtCameraParameters, output);