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 
8 class CByteImage;
9 
10 namespace 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, cv::Mat& output);
70 
71  /**
72  * @brief Builds a camera matrix.
73  * @param cameraParams The camera matrix.
74  * @return The CV camera matrix.
75  */
76  template <class CameraParams>
77  cv::Mat makeCameraMatrix(const CameraParams& cameraParams,
78  int rows = 3, int cols = 3, int type = CV_64F)
79  {
80  cv::Mat cameraMatrix = cv::Mat(rows, cols, type, 0.0);
81  fillCameraMatrix(cameraParams, cameraMatrix);
82  return cameraMatrix;
83  }
84 
85 }
visionx::convertDepthInMetersToWeirdArmarX
void convertDepthInMetersToWeirdArmarX(const cv::Mat &input, CByteImage *output)
Definition: OpenCVUtil.cpp:98
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::convertWeirdArmarXToDepthInMeters
cv::Mat convertWeirdArmarXToDepthInMeters(CByteImage const *input)
Convert ArmarX encoding of depth information in an RGB image to depth in meters.
Definition: OpenCVUtil.cpp:61
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
visionx::copyCvDepthToGrayscaleIVT
void copyCvDepthToGrayscaleIVT(cv::Mat const &inputInMeters, CByteImage *output)
Copies a floating point depth image (in meters) to an RGB depth representation.
Definition: OpenCVUtil.cpp:26
visionx::copyCvMatToIVT
void copyCvMatToIVT(cv::Mat const &input, CByteImage *output)
Copies the contents of an OpenCV matrix to an IVT CByteImage.
Definition: OpenCVUtil.cpp:13
visionx::makeCameraMatrix
cv::Mat makeCameraMatrix(const visionx::CameraParameters &cameraParams)
Definition: opencv_conversions.cpp:25
visionx::fillCameraMatrix
void fillCameraMatrix(const visionx::CameraParameters &cameraParams, cv::Mat &output)
Fill a propertly initialized camera matrix with the given camera parameters.
Definition: OpenCVUtil.cpp:195