aron_conversions.cpp
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 #include "aron_conversions.h"
24 
26 
27 
28 namespace visionx::armem::camera
29 {
30  visionx::StereoCalibration
31  fromAron(visionx::StereoCalibration& bo, visionx::arondto::StereoCameraCalibration& dto){
32 
33  //Parameters for the left calibration:
34  visionx::MonocularCalibration left;
35  visionx::CameraParameters leftParams;
36  leftParams.width = dto.calibrationLeft.cameraParam.width;
37  leftParams.height = dto.calibrationLeft.cameraParam.height;
38  Eigen::Vector2f pp = dto.calibrationLeft.cameraParam.principalPoint;
39  leftParams.principalPoint = visionx::tools::convertEigenVecToVisionX(pp);
40 
41  Eigen::Vector2f fl = dto.calibrationLeft.cameraParam.focalLength;
42  leftParams.focalLength = visionx::tools::convertEigenVecToVisionX(fl);
43  //Note: there is a mismatch between distortion parameters in visionx and aron
44  //aron does differentiate between radial and tangential distortion, visionx does not
45  //for now the distortion is simply set to zero, as this is done when using it anyways
46  Eigen::Vector4f rd;
47  rd.setZero();
48  leftParams.distortion = visionx::tools::convertEigenVecToVisionX(rd);
49  Eigen::Matrix3f rot = dto.calibrationLeft.cameraParam.rotation;
50  leftParams.rotation = visionx::tools::convertEigenMatToVisionX(rot);
51  Eigen::Vector3f trans = dto.calibrationLeft.cameraParam.translation;
52  leftParams.translation = visionx::tools::convertEigenVecToVisionX(trans);
53  left.cameraParam = leftParams;
54 
55  //Parameters for the right calibration:
56  visionx::MonocularCalibration right;
57  visionx::CameraParameters rightParams;
58  rightParams.width = dto.calibrationRight.cameraParam.width;
59  rightParams.height = dto.calibrationRight.cameraParam.height;
60 
61  Eigen::Vector2f ppr = dto.calibrationRight.cameraParam.principalPoint;
62  rightParams.principalPoint = visionx::tools::convertEigenVecToVisionX(ppr);
63 
64  Eigen::Vector2f flr = dto.calibrationRight.cameraParam.focalLength;
65  rightParams.focalLength = visionx::tools::convertEigenVecToVisionX(flr);
66  Eigen::Vector4f rdr;
67  rdr.setZero();
68  rightParams.distortion = visionx::tools::convertEigenVecToVisionX(rdr);
69  Eigen::Matrix3f rotr = dto.calibrationRight.cameraParam.rotation;
70  rightParams.rotation = visionx::tools::convertEigenMatToVisionX(rotr);
71  Eigen::Vector3f transr = dto.calibrationRight.cameraParam.translation;
72  rightParams.translation = visionx::tools::convertEigenVecToVisionX(transr);
73  right.cameraParam = rightParams;
74 
75  //Setting rectification of homograpy:
76  Eigen::Matrix3f rHL = dto.rectificationHomographyLeft;
77  bo.rectificationHomographyLeft = visionx::tools::convertEigenMatToVisionX(rHL);
78  Eigen::Matrix3f rHR = dto.rectificationHomographyRight;
79  bo.rectificationHomographyRight = visionx::tools::convertEigenMatToVisionX(rHR);
80  bo.calibrationLeft = left;
81  bo.calibrationRight = right;
82 
83  return bo;
84 
85  }
86 
87  visionx::arondto::StereoCameraCalibration
88  toAron(visionx::arondto::StereoCameraCalibration& dto, visionx::StereoCalibration& bo){
89 
90  visionx::arondto::MonocularCameraCalibration left;
91  visionx::arondto::CameraParameters leftParams;
92 
93  //set all parameters for left camera calibration:
94  leftParams.height = bo.calibrationLeft.cameraParam.height;
95  leftParams.width = bo.calibrationLeft.cameraParam.width;
96 
97  leftParams.focalLength = visionx::tools::convertVisionXVecToEigen(bo.calibrationLeft.cameraParam.focalLength);
98  leftParams.principalPoint = visionx::tools::convertVisionXVecToEigen(bo.calibrationLeft.cameraParam.principalPoint);
99  leftParams.radialDistortion = visionx::types::Vec(); //due to mismatch in types and non-usage of this anyways
100  //leftParams.tangentialDistortion; due to mismatch in types and non-usage of this anyways
101  leftParams.rotation = visionx::tools::convertVisionXMatToEigen(bo.calibrationLeft.cameraParam.rotation);
102  leftParams.translation = visionx::tools::convertVisionXVecToEigen(bo.calibrationLeft.cameraParam.translation);
103 
104  //left camera just needs the parameters assigned:
105  left.cameraParam = leftParams;
106 
107  visionx::arondto::MonocularCameraCalibration right;
108  visionx::arondto::CameraParameters rightParams;
109 
110  //set all parameters for right camera calibration:
111  rightParams.height = bo.calibrationRight.cameraParam.height;
112  rightParams.width = bo.calibrationRight.cameraParam.width;
113 
114  rightParams.focalLength = visionx::tools::convertVisionXVecToEigen(bo.calibrationRight.cameraParam.focalLength);
115  rightParams.principalPoint = visionx::tools::convertVisionXVecToEigen(bo.calibrationRight.cameraParam.principalPoint);
116  rightParams.radialDistortion = visionx::types::Vec(); //due to mismatch in types and non-usage of this anyways
117  //rightParams.tangentialDistortion; due to mismatch in types and non-usage of this anyways
118  rightParams.rotation = visionx::tools::convertVisionXMatToEigen(bo.calibrationRight.cameraParam.rotation);
119  rightParams.translation = visionx::tools::convertVisionXVecToEigen(bo.calibrationRight.cameraParam.translation);
120 
121  //right camera just needs the parameters assigned:
122  right.cameraParam = rightParams;
123 
124  auto rectificationHomographyLeft = bo.rectificationHomographyLeft;
125  auto rectificationHomographyRight = bo.rectificationHomographyRight;
126 
127  dto.rectificationHomographyLeft = visionx::tools::convertVisionXMatToEigen(rectificationHomographyLeft);
128  dto.rectificationHomographyRight = visionx::tools::convertVisionXMatToEigen(rectificationHomographyRight);
129  dto.calibrationLeft = left;
130  dto.calibrationRight = right;
131 
132  return dto;
133  }
134 }
visionx::tools::convertVisionXMatToEigen
Eigen::MatrixXf convertVisionXMatToEigen(visionx::types::Mat m)
Definition: TypeMapping.cpp:691
visionx::armem::camera::toAron
visionx::arondto::StereoCameraCalibration toAron(visionx::arondto::StereoCameraCalibration &dto, visionx::StereoCalibration &bo)
Definition: aron_conversions.cpp:88
visionx::armem::camera
Definition: constants.cpp:3
visionx::tools::convertEigenVecToVisionX
visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v)
Definition: TypeMapping.cpp:655
visionx::armem::camera::fromAron
visionx::StereoCalibration fromAron(visionx::StereoCalibration &bo, visionx::arondto::StereoCameraCalibration &dto)
Definition: aron_conversions.cpp:31
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
visionx::tools::convertVisionXVecToEigen
Eigen::VectorXf convertVisionXVecToEigen(visionx::types::Vec v)
Definition: TypeMapping.cpp:666
visionx::tools::convertEigenMatToVisionX
visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m)
Definition: TypeMapping.cpp:677
aron_conversions.h
TypeMapping.h
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168