7 #include <VisionX/interface/components/Calibration.h>
9 #include <Image/ByteImage.h>
19 int imageSize = output->width * output->height * output->bytesPerPixel;
22 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;
67 int width =
input->width;
68 int height =
input->height;
69 cv::Mat result(height, width, CV_32FC1);
81 const unsigned char* inputRow =
input;
82 for (
int row = 0; row < output.rows; ++row)
84 float* outputRow = output.ptr<
float>(row);
85 for (
int col = 0; col < output.cols; ++col)
88 int r = inputRow[col * 3 + 0];
89 int g = inputRow[col * 3 + 1];
90 int depthInMM = (g << 8) + r;
91 outputRow[col] =
static_cast<float>(depthInMM) / 1000.0f;
94 inputRow += output.cols * 3;
107 const auto height = output->height;
108 const auto width = output->width;
110 unsigned char* outputRow = output->pixels;
111 for (
int y = 0; y < height; ++y)
113 const float* inputRow =
input.ptr<
float>(y);
114 for (
int x = 0; x < width; ++x)
116 const auto depthInMM = inputRow[x] * 1000;
118 outputRow[x * 3 + 0] =
static_cast<unsigned char>(std::fmod(depthInMM, 256));
119 outputRow[x * 3 + 1] =
static_cast<unsigned char>(std::fmod(depthInMM / 256, 256));
120 outputRow[x * 3 + 2] =
121 static_cast<unsigned char>(std::fmod(depthInMM / 256 / 256, 256));
124 inputRow += width * 3;
130 template <
typename Float>
134 output.at<
Float>(0, 1) = 0;
135 output.at<
Float>(1, 0) = 0;
136 output.at<
Float>(2, 0) = 0;
137 output.at<
Float>(2, 1) = 0;
138 output.at<
Float>(2, 2) = 1;
144 if (!(matrix.depth() == CV_32F || matrix.depth() == CV_64F))
146 std::stringstream ss;
147 ss <<
"Passed " << semanticName <<
" must be floating point type, "
148 <<
"i.e. CV_32F (" << CV_32F <<
") or CV_64F (" << CV_64F <<
"), "
149 <<
"but its type was " << matrix.type() <<
".";
150 throw std::invalid_argument(ss.str());
162 template <
typename Float>
164 fillCameraMatrix(
const CCalibration::CCameraParameters& ivtCameraParameters, cv::Mat& output)
168 fillEmptyValues<Float>(output);
170 output.at<
Float>(0, 0) =
Float(ivtCameraParameters.focalLength.x);
171 output.at<
Float>(0, 2) =
Float(ivtCameraParameters.principalPoint.x);
172 output.at<
Float>(1, 1) =
Float(ivtCameraParameters.focalLength.y);
173 output.at<
Float>(1, 2) =
Float(ivtCameraParameters.principalPoint.y);
176 template <
typename Float>
185 const float nodalPointX = cameraParams.principalPoint.at(0);
186 const float nodalPointY = cameraParams.principalPoint.at(1);
187 const float focalLengthX = cameraParams.focalLength.at(0);
188 const float focalLengthY = cameraParams.focalLength.at(1);
190 fillEmptyValues<Float>(output);
204 if (output.depth() == CV_32F)
206 detail::fillCameraMatrix<float>(cameraParams, output);
208 else if (output.depth() == CV_64F)
210 detail::fillCameraMatrix<double>(cameraParams, output);
219 if (output.depth() == CV_32F)
221 detail::fillCameraMatrix<float>(ivtCameraParameters, output);
223 else if (output.depth() == CV_64F)
225 detail::fillCameraMatrix<double>(ivtCameraParameters, output);