ScanCamera.hpp
Go to the documentation of this file.
1 
2 #ifndef LVR2_IO_YAML_PINHOLECAMERAMODEL_IO_HPP
3 #define LVR2_IO_YAML_PINHOLECAMERAMODEL_IO_HPP
4 
5 #include <sstream>
6 
7 #include <yaml-cpp/yaml.h>
9 #include "MatrixIO.hpp"
11 
12 namespace YAML {
13 
20 // WRITE SCAN PARTIALLY
21 template<>
22 struct convert<lvr2::ScanCamera>
23 {
24 
28  static Node encode(const lvr2::ScanCamera& scanCam) {
29 
30  Node node;
31  node["sensor_type"] = lvr2::ScanCamera::sensorType;
32  node["sensor_name"] = scanCam.sensorName;
33  node["camera_model"] = "pinhole";
34  node["distortion_model"] = scanCam.camera.distortionModel;
35  node["resolution"] = Load("[]");
36  node["resolution"].push_back(scanCam.camera.width);
37  node["resolution"].push_back(scanCam.camera.height);
38 
39  Node pinholeNode;
40  pinholeNode["cx"] = scanCam.camera.cx;
41  pinholeNode["cy"] = scanCam.camera.cy;
42  pinholeNode["fx"] = scanCam.camera.fx;
43  pinholeNode["fy"] = scanCam.camera.fy;
44  node["pinhole"] = pinholeNode;
45 
46  if(scanCam.camera.distortionModel == "opencv")
47  {
48  Node distortion;
49  for(size_t i = 0; i < scanCam.camera.k.size(); i++)
50  {
51  std::stringstream s;
52  s << "k" << i;
53  distortion[s.str()] = scanCam.camera.k[i];
54  }
55  node["distortion"] = distortion;
56  } else {
57  // unkown distortion model
58  }
59 
60 
61 
62 
63  return node;
64  }
65 
66  static bool decode(const Node& node, lvr2::ScanCamera& scanCam)
67  {
68  // Check if we are reading camera information
69  if(node["sensor_type"].as<std::string>() != lvr2::ScanCamera::sensorType)
70  {
71  return false;
72  }
73 
74  if(node["sensor_name"])
75  {
76  scanCam.sensorName = node["sensor_name"].as<std::string>();
77  }
78  else
79  {
80  scanCam.sensorName = "noname";
81  }
82 
83  if(node["resolution"] && node["resolution"].size() == 2)
84  {
85  scanCam.camera.width = node["resolution"][0].as<unsigned>();
86  scanCam.camera.height = node["resolution"][1].as<unsigned>();
87  }
88 
89  std::string camera_model = node["camera_model"].as<std::string>();
90 
91  if(camera_model == "pinhole")
92  {
93  // load pinhole parameters
94  Node pinholeNode = node["pinhole"];
95  scanCam.camera.cx = pinholeNode["cx"].as<double>();
96  scanCam.camera.cy = pinholeNode["cy"].as<double>();
97  scanCam.camera.fx = pinholeNode["fx"].as<double>();
98  scanCam.camera.fy = pinholeNode["fy"].as<double>();
99  } else {
100  std::cout << "Camera model unknown" << std::endl;
101  }
102 
103  // Check if we have distortion data in OpenCV format
104 
105  scanCam.camera.distortionModel = node["distortion_model"].as<std::string>();
106 
107  if(scanCam.camera.distortionModel == "opencv")
108  {
109  Node distortionNode = node["distortion"];
110  scanCam.camera.k.clear();
111  if(distortionNode)
112  {
113  for(size_t i = 0; i < distortionNode.size(); i++)
114  {
115  std::cout << i << std::endl;
116  scanCam.camera.k.push_back(distortionNode[i].as<double>());
117  }
118  }
119  } else {
120  std::cout << "Distortion model unknown" << std::endl;
121  }
122 
123 
124 
125 
126  return true;
127  }
128 
129 };
130 
131 } // namespace YAML
132 
133 #endif // LVR2_IO_YAML_PINHOLECAMERAMODEL_IO_HPP
134 
lvr2::ScanCamera::camera
PinholeModeld camera
Pinhole camera model.
Definition: ScanTypes.hpp:153
lvr2::ScanCamera::sensorName
std::string sensorName
Individual name of the camera.
Definition: ScanTypes.hpp:150
lvr2::PinholeModel::fx
double fx
Definition: CameraModels.hpp:16
lvr2::ScanCamera::sensorType
static constexpr char sensorType[]
Description of the sensor model.
Definition: ScanTypes.hpp:147
CameraModels.hpp
lvr2::PinholeModel::width
unsigned width
Definition: CameraModels.hpp:20
YAML
Definition: LSROptionsYamlExtensions.hpp:42
lvr2::PinholeModel::k
std::vector< T > k
Definition: CameraModels.hpp:22
ScanTypes.hpp
YAML::convert< lvr2::ScanCamera >::decode
static bool decode(const Node &node, lvr2::ScanCamera &scanCam)
Definition: ScanCamera.hpp:66
lvr2::ScanCamera
Definition: ScanTypes.hpp:138
lvr2::convert
void convert(COORD_SYSTEM from, COORD_SYSTEM to, float *point)
Definition: CoordinateTransform.cpp:46
lvr2::PinholeModel::cx
double cx
Definition: CameraModels.hpp:18
lvr2::PinholeModel::height
unsigned height
Definition: CameraModels.hpp:21
MatrixIO.hpp
lvr2
Definition: BaseBufferManipulators.hpp:39
YAML::convert< lvr2::ScanCamera >::encode
static Node encode(const lvr2::ScanCamera &scanCam)
Definition: ScanCamera.hpp:28
lvr2::PinholeModel::cy
double cy
Definition: CameraModels.hpp:19
lvr2::PinholeModel::fy
double fy
Definition: CameraModels.hpp:17
lvr2::PinholeModel::distortionModel
std::string distortionModel
Definition: CameraModels.hpp:23


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:24