OpenCVUtil.h
Go to the documentation of this file.
1#pragma once
2
3#include <opencv2/core/core.hpp>
4
5#include <Calibration/Calibration.h>
6
7
8class CByteImage;
9
10namespace visionx
11{
12
13 /**
14 * @brief Copies the contents of an OpenCV matrix to an IVT CByteImage.
15 *
16 * @param input OpenCV matrix (RGB or grayscale)
17 * @param output IVT CByteImage (RGB or grayscale)
18 */
19 void copyCvMatToIVT(cv::Mat const& input, CByteImage* output);
20
21 /**
22 * @brief Copies a floating point depth image (in meters) to an RGB depth representation.
23 * Close to the camera: White
24 * Farther away: Black
25 *
26 * @param inputInMeters OpenCV floating point matrix (CV_32FC1) containting depth in meters.
27 * @param output IVT CByteImage for visulaizing the depth info in an RGB image.
28 */
29 void copyCvDepthToGrayscaleIVT(cv::Mat const& inputInMeters, CByteImage* output);
30
31
32 /**
33 * @brief Convert ArmarX encoding of depth information in an RGB image to depth in meters.
34 *
35 * ArmarX stores the depth in mm in the R and G channel of an RGB image.
36 * This is due to the fact that we cannot provide images of different types.
37 * So a RGB-D camera needs to use a single format for both color and depth.
38 *
39 * @param input Weird ArmarX encoding of depth image.
40 * @return Floating point matrix containing the depth in meters.
41 */
42 cv::Mat convertWeirdArmarXToDepthInMeters(CByteImage const* input);
43
44 /**
45 * @brief Like `convertWeirdArmarXToDepthInMeters(CByteImage const* input)`,
46 * but writes into a pre-initialized cv::Mat with the correct size and type.
47 *
48 * @param input The raw pixel buffer with weird ArmarX depth encoding.
49 * @param output A cv::Mat with the correct size and type.
50 */
51 void convertWeirdArmarXToDepthInMeters(const uint8_t* input, cv::Mat& output);
52
53 void convertDepthInMetersToWeirdArmarX(const cv::Mat& input, CByteImage* output);
54
55
56 class CameraParameters;
57
58 /**
59 * @brief Fill a propertly initialized camera matrix with the given camera parameters.
60 * @param cameraParams The camera parameters.
61 * @param output The cv matrix. Must be floating point, i.e. CV_32F or CV_64F.
62 */
63 void fillCameraMatrix(const visionx::CameraParameters& cameraParams, cv::Mat& output);
64 /**
65 * @brief Fill a propertly initialized camera matrix with the given camera parameters.
66 * @param cameraParams The camera parameters.
67 * @param output The cv matrix. Must be floating point, i.e. CV_32F or CV_64F.
68 */
69 void fillCameraMatrix(const CCalibration::CCameraParameters& ivtCameraParameters,
70 cv::Mat& output);
71
72 /**
73 * @brief Builds a camera matrix.
74 * @param cameraParams The camera matrix.
75 * @return The CV camera matrix.
76 */
77 template <class CameraParams>
78 cv::Mat
79 makeCameraMatrix(const CameraParams& cameraParams,
80 int rows = 3,
81 int cols = 3,
82 int type = CV_64F)
83 {
84 cv::Mat cameraMatrix = cv::Mat(rows, cols, type, 0.0);
85 fillCameraMatrix(cameraParams, cameraMatrix);
86 return cameraMatrix;
87 }
88
89} // namespace visionx
ArmarX headers.
cv::Mat makeCameraMatrix(const visionx::CameraParameters &cameraParams)
void convertDepthInMetersToWeirdArmarX(const cv::Mat &input, CByteImage *output)
cv::Mat convertWeirdArmarXToDepthInMeters(CByteImage const *input)
Convert ArmarX encoding of depth information in an RGB image to depth in meters.
void copyCvDepthToGrayscaleIVT(cv::Mat const &inputInMeters, CByteImage *output)
Copies a floating point depth image (in meters) to an RGB depth representation.
void fillCameraMatrix(const visionx::CameraParameters &cameraParams, cv::Mat &output)
Fill a propertly initialized camera matrix with the given camera parameters.
void copyCvMatToIVT(cv::Mat const &input, CByteImage *output)
Copies the contents of an OpenCV matrix to an IVT CByteImage.