12#ifndef IMAGE_OPERATIONS_HPP
13#define IMAGE_OPERATIONS_HPP
16#include <opencv2/opencv.hpp>
17#include <sl/Camera.hpp>
48 case sl::MAT_TYPE::F32_C1: nOpenCVType =
CV_32FC1;
break;
49 case sl::MAT_TYPE::F32_C2: nOpenCVType =
CV_32FC2;
break;
50 case sl::MAT_TYPE::F32_C3: nOpenCVType =
CV_32FC3;
break;
51 case sl::MAT_TYPE::F32_C4: nOpenCVType =
CV_32FC4;
break;
52 case sl::MAT_TYPE::U16_C1: nOpenCVType =
CV_16SC1;
break;
53 case sl::MAT_TYPE::U8_C1: nOpenCVType =
CV_8UC1;
break;
54 case sl::MAT_TYPE::U8_C2: nOpenCVType =
CV_8UC2;
break;
55 case sl::MAT_TYPE::U8_C3: nOpenCVType =
CV_8UC3;
break;
56 case sl::MAT_TYPE::U8_C4: nOpenCVType =
CV_8UC4;
break;
76 sl::MAT_TYPE slMatType = sl::MAT_TYPE::U8_C1;
81 case CV_32FC1: slMatType = sl::MAT_TYPE::F32_C1;
break;
82 case CV_32FC2: slMatType = sl::MAT_TYPE::F32_C2;
break;
83 case CV_32FC3: slMatType = sl::MAT_TYPE::F32_C3;
break;
84 case CV_32FC4: slMatType = sl::MAT_TYPE::F32_C4;
break;
85 case CV_16SC1: slMatType = sl::MAT_TYPE::U16_C1;
break;
86 case CV_8UC1: slMatType = sl::MAT_TYPE::U8_C1;
break;
87 case CV_8UC2: slMatType = sl::MAT_TYPE::U8_C2;
break;
88 case CV_8UC3: slMatType = sl::MAT_TYPE::U8_C3;
break;
89 case CV_8UC4: slMatType = sl::MAT_TYPE::U8_C4;
break;
110 return cv::Mat(slInputMat.getHeight(),
111 slInputMat.getWidth(),
113 slInputMat.getPtr<sl::uchar1>(sl::MEM::CPU),
114 slInputMat.getStepBytes(sl::MEM::CPU));
132 slInputMat.getWidth(),
134 slInputMat.getPtr<sl::uchar1>(sl::MEM::GPU),
135 slInputMat.getStepBytes(sl::MEM::GPU));
184 if (cvOutputColors.
empty())
190 else if (cvOutputColors.
rows != cvInputPointCloud.
rows || cvOutputColors.
cols != cvInputPointCloud.
cols || cvOutputColors.
channels() != 4)
193 LOG_ERROR(logging::g_qSharedLogger,
194 "SplitPointCloudColors: The given point cloud cv::Mat and output colors cv::Mat do not have the same dimensions! Dimensions are: (height = {} and "
195 "{}) (width = {} and {}) (channels = {} and {})",
196 cvInputPointCloud.
rows,
198 cvInputPointCloud.
cols,
207 for (
int nY = 0; nY < cvInputPointCloud.
rows; ++nY)
209 for (
int nX = 0; nX < cvInputPointCloud.
cols; ++nX)
212 unsigned int unColor = *
reinterpret_cast<unsigned int*
>(&cvInputPointCloud.
at<
cv::Vec4f>(nY, nX)[3]);
214 unsigned char ucB = (unColor >> 0) & 0xFF;
215 unsigned char ucG = (unColor >> 8) & 0xFF;
216 unsigned char ucR = (unColor >> 16) & 0xFF;
217 unsigned char ucA = (unColor >> 24) & 0xFF;
242 for (
int y = 0; y <
rows; y++)
244 for (
int x = 0; x <
cols; x++)
246 double sumIntensity = 0.0;
247 double sumWeight = 0.0;
251 for (
int j = -usDiameter; j <= usDiameter; j++)
253 for (
int i = -usDiameter; i <= usDiameter; i++)
255 int neighborX = x + i;
256 int neighborY = y + j;
259 if (neighborX >= 0 && neighborX < cols && neighborY >= 0 && neighborY <
rows)
261 uchar neighborPixel = cvInputFrame.
at<
uchar>(neighborY, neighborX);
264 double spatialWeight = std::exp(-(i * i + j * j) / (2 * dSigmaSpace * dSigmaSpace));
267 uchar colorDistance = std::abs(centerPixel - neighborPixel);
268 double intensityWeight = std::exp(-(colorDistance * colorDistance) / (2 * dSigmaColor * dSigmaColor));
271 double bilateralWeight = spatialWeight * intensityWeight;
273 sumIntensity += bilateralWeight * neighborPixel;
274 sumWeight += bilateralWeight;
280 uchar filteredPixel = sumIntensity / sumWeight;
281 cvInputFrame.
at<
uchar>(y, x) = filteredPixel;
298 int nLines = cvFrame.
rows;
303 for (
int nI = 0; nI < nLines; nI++)
309 for (
int nJ = 0; nJ < nElements; nJ++)
312 chData[nJ] = chData[nJ] / nDiv * nDiv + nDiv / 2;
Namespace containing functions related to GENERAL operations on images or other large binary operatio...
Definition ImageOperations.hpp:30
sl::Mat ConvertCVMatToSLMat(cv::Mat &cvInputMat)
Convert an OpenCV cv::Mat object into a ZEDSDK sl::Mat object. This copies the mat from CPU memory to...
Definition ImageOperations.hpp:148
cv::cuda::GpuMat ConvertSLMatToGPUMat(sl::Mat &slInputMat)
Convert a ZEDSDK sl::Mat object into an OpenCV cv::cuda::GpuMat object. Keeps all Mat memory in GPU V...
Definition ImageOperations.hpp:127
sl::MAT_TYPE GetCVToOpenSLMatType(const int cvType)
Provides an easy method of mapping cv::Mat types to sl::Mat types.
Definition ImageOperations.hpp:73
void SplitPointCloudColors(cv::Mat &cvInputPointCloud, cv::Mat &cvOutputColors)
Given a cv::Mat containing X, Y, Z, and BGRA values for each pixel in the third dimension,...
Definition ImageOperations.hpp:181
sl::Mat ConvertGPUMatToSLMat(cv::cuda::GpuMat &cvInputMat)
Convert an OpenCV cv::Mat object into a ZEDSDK sl::Mat object. This copies the mat from CPU memory to...
Definition ImageOperations.hpp:164
void ColorReduce(cv::Mat &cvFrame, int nDiv=64)
Given an image and a divisor, divide the precision of the elements.
Definition ImageOperations.hpp:295
void CustomBilateralFilter(cv::Mat &cvInputFrame, ushort usDiameter, double dSigmaColor, double dSigmaSpace)
Custom implementation of bilateral filter (since openCV is slow)
Definition ImageOperations.hpp:237
int GetSLToOpenCVMatType(const sl::MAT_TYPE slType)
Provides an easy method of mapping sl::Mat types to cv::Mat types.
Definition ImageOperations.hpp:40
cv::Mat ConvertSLMatToCVMat(sl::Mat &slInputMat)
Convert a ZEDSDK sl::Mat object into an OpenCV cv::Mat object. This copies the mat from GPU memory to...
Definition ImageOperations.hpp:106