aron_conversions.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::ArmarXObjects::armem_images
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 // RobotAPI
27 
28 // IVT
30 
31 #include <Image/ByteImage.h>
32 
33 // Aron
34 #include <VisionX/libraries/armem/vision/images/core/aron/ImageDepth.aron.generated.h>
35 #include <VisionX/libraries/armem/vision/images/core/aron/ImageRGB.aron.generated.h>
36 
37 namespace visionx::armem_images
38 {
39  template <class AronImageT>
40  void
41  to_aron(AronImageT& dto, void*& bo)
42  {
43  cv::Mat& mat = dto.image;
44  switch (mat.type())
45  {
46  case CV_8UC3: // Rgb24
47  mat = cv::Mat(mat.rows, mat.cols, mat.type(), bo);
48  break;
49 
50  case CV_32FC1: // Depth32
51  visionx::convertWeirdArmarXToDepthInMeters(reinterpret_cast<uint8_t*>(bo), mat);
52  break;
53  }
54  }
55 
56  template <class AronImageT>
57  void
58  to_aron(AronImageT& dto, const CByteImage& bo)
59  {
60  cv::Mat& mat = dto.image;
61  switch (mat.type())
62  {
63  case CV_8UC3: // Rgb24
64  mat = cv::Mat(bo.height, bo.width, mat.type(), bo.pixels);
65  break;
66 
67  case CV_32FC1: // Depth32
69  break;
70  }
71  }
72 
73  template <class AronImageT>
74  void
75  from_aron(const AronImageT& dto, CByteImage& bo)
76  {
77  bool headerOnly = true;
78  const cv::Mat& mat = dto.image;
79  switch (mat.type())
80  {
81  case CV_8UC3: // Rgb24
82  bo = CByteImage(mat.cols, mat.rows, CByteImage::eRGB24, headerOnly);
83  bo.pixels = mat.data;
84  break;
85 
86  case CV_32FC1: // Depth32
87  bo = CByteImage(mat.cols, mat.rows, CByteImage::eRGB24);
89  break;
90  }
91  }
92 
93  template <class AronImageT>
94  void
95  to_aron(AronImageT& dto, const cv::Mat& bo)
96  {
97  dto.image = bo;
98  }
99 
100  template <class AronImageT>
101  void
102  from_aron(const AronImageT& dto, cv::Mat& bo)
103  {
104  bo = dto.image;
105  }
106 } // namespace visionx::armem_images
visionx::convertDepthInMetersToWeirdArmarX
void convertDepthInMetersToWeirdArmarX(const cv::Mat &input, CByteImage *output)
Definition: OpenCVUtil.cpp:98
visionx::armem_images::from_aron
void from_aron(const AronImageT &dto, CByteImage &bo)
Definition: aron_conversions.h:75
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
visionx::armem_images
Definition: ImageReader.cpp:29
forward_declarations.h
visionx::armem_images::to_aron
void to_aron(AronImageT &dto, void *&bo)
Definition: aron_conversions.h:41
OpenCVUtil.h
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168