Ocean
Loading...
Searching...
No Matches
CameraCalibrationManager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_IO_CAMERA_CALIBRATION_MANAGER_H
9#define META_OCEAN_IO_CAMERA_CALIBRATION_MANAGER_H
10
11#include "ocean/io/IO.h"
12
14
16
17#include <map>
18
19namespace Ocean
20{
21
22namespace IO
23{
24
25/**
26 * This class implements a camera calibration manager as singleton.<br>
27 * The manager organizes camera calibrations with different dimensions.<br>
28 * @ingroup io
29 */
30class OCEAN_IO_EXPORT CameraCalibrationManager : public Singleton<CameraCalibrationManager>
31{
33
34 public:
35
36 /**
37 * Definition of different priority values for the camera calibrations.
38 */
40 {
41 /// Low priority
43 /// Medium priority
45 /// High priority
47 /// Explicit use priority
48 PRIORITY_EXPLICIT
49 };
50
51 /**
52 * Definition of different calibration qualities.
53 */
55 {
56 /// Exact calibration
58 /// Interpolated calibration
60 /// Default calibration
61 QUALITY_DEFAULT
62 };
63
64 protected:
65
66 /**
67 * Device calibration object.
68 */
69 class Device
70 {
72
73 protected:
74
75 /**
76 * Definition of a image resolution.
77 */
78 typedef std::pair<unsigned int, unsigned int> Resolution;
79
80 /**
81 * Definition of a pair of camera and priority values.
82 */
83 typedef std::pair<PinholeCamera, Priority> CameraPair;
84
85 /**
86 * Definition of a map mapping image resolutions to camera objects.
87 */
88 typedef std::map<Resolution, CameraPair> ResolutionMap;
89
90 public:
91
92 /**
93 * Returns a calibration for a specific frame resolution.
94 * @param width The width of the frame in pixel, with range [1, infinity)
95 * @param height The height of the frame in pixel, with range [1, infinity)
96 * @param quality Optional resulting quality of the calibration
97 * @param defaultFovX The default horizontal field of view the resulting camera profile will provide if no camera calibration exists for the specified resolution, with range (0, PI)
98 * @return The camera for the given resolution
99 */
100 PinholeCamera camera(const unsigned int width, const unsigned int height, Quality* quality, const Scalar defaultFovX = Numeric::deg2rad(45)) const;
101
102 protected:
103
104 /**
105 * Adds a new calibration for a specific frame resolution.
106 * @param camera The camera object
107 * @param priority Priority of the calibration
108 * @return True, if succeeded
109 */
110 bool addResolution(const PinholeCamera& camera, const Priority priority);
111
112 protected:
113
114 /// Resolution map.
116 };
117
118 /**
119 * Definition of a map mapping device names to device objects.
120 */
121 typedef std::map<std::string, Device> DeviceMap;
122
123 /**
124 * Definition of a map mapping alias device names to device names.
125 */
126 typedef std::map<std::string, std::string> AliasMap;
127
128 public:
129
130 /**
131 * Registers a new camera calibration.
132 * @param camera Name or url of the camera to register
133 * @param width The width of the camera resolution in pixel, with range [1, infinity)
134 * @param height The height of the camera resolution in pixel, with range [1, infinity)
135 * @param fovX Horizontal field of view in radian, with range (0, PI)
136 * @return True, if succeeded
137 */
138 bool registerCalibration(const std::string& camera, const unsigned int width, const unsigned int height, const Scalar fovX);
139
140 /**
141 * Registers a new camera calibration file.
142 * The file must have a specific file format.
143 * @param url Url of the calibration file
144 * @return True, if succeeded
145 */
146 bool registerCalibrationFile(const std::string& url);
147
148 /**
149 * Registers a new camera calibration.
150 * This explicit calibration will receive the highest priority.
151 * @param camera Name of the device or camera
152 * @param calibration The camera calibration profile
153 * @return True, if succeeded
154 */
155 bool registerCalibration(const std::string& camera, const PinholeCamera& calibration);
156
157 /**
158 * Registers an alias camera name.
159 * @param camera Original camera name
160 * @param alias Alias camera name
161 * @return True, if succeeded
162 */
163 bool registerAlias(const std::string& camera, const std::string& alias);
164
165 /**
166 * Returns a calibration for a specific device with a specific frame resolution.
167 * @param device Name of the device
168 * @param width The width of the frame in pixel, with range [1, infinity)
169 * @param height The height of the frame in pixel, with range [1, infinity)
170 * @param quality Optional resulting quality of the calibration
171 * @param defaultFovX The default horizontal field of view the resulting camera profile will provide if no camera calibration exists for the specified device, with range (0, PI)
172 * @return The camera profile for the given resolution
173 */
174 PinholeCamera camera(const std::string& device, const unsigned int width, const unsigned int height, Quality* quality = nullptr, const Scalar defaultFovX = Numeric::deg2rad(45)) const;
175
176 /**
177 * Returns whether this manager holds a valid camera profile for a specified device.
178 * @param device The name of the device to check
179 * @return True, if so
180 */
181 bool hasCalibration(const std::string& device) const;
182
183 protected:
184
185 /**
186 * Creates a new manager.
187 */
189
190 /**
191 * Destructs the manager.
192 */
194
195 protected:
196
197 /// Map holding all registered devices.
199
200 /// Map holding alias names.
202
203 /// The lock of this manager.
204 mutable Lock lock_;
205};
206
207}
208
209}
210
211#endif // META_OCEAN_IO_CAMERA_CALIBRATION_MANAGER_H
Device calibration object.
Definition CameraCalibrationManager.h:70
ResolutionMap resolutionMap_
Resolution map.
Definition CameraCalibrationManager.h:115
bool addResolution(const PinholeCamera &camera, const Priority priority)
Adds a new calibration for a specific frame resolution.
PinholeCamera camera(const unsigned int width, const unsigned int height, Quality *quality, const Scalar defaultFovX=Numeric::deg2rad(45)) const
Returns a calibration for a specific frame resolution.
std::map< Resolution, CameraPair > ResolutionMap
Definition of a map mapping image resolutions to camera objects.
Definition CameraCalibrationManager.h:88
std::pair< PinholeCamera, Priority > CameraPair
Definition of a pair of camera and priority values.
Definition CameraCalibrationManager.h:83
std::pair< unsigned int, unsigned int > Resolution
Definition of a image resolution.
Definition CameraCalibrationManager.h:78
This class implements a camera calibration manager as singleton.
Definition CameraCalibrationManager.h:31
bool hasCalibration(const std::string &device) const
Returns whether this manager holds a valid camera profile for a specified device.
AliasMap aliasMap_
Map holding alias names.
Definition CameraCalibrationManager.h:201
bool registerCalibration(const std::string &camera, const PinholeCamera &calibration)
Registers a new camera calibration.
bool registerAlias(const std::string &camera, const std::string &alias)
Registers an alias camera name.
~CameraCalibrationManager()
Destructs the manager.
bool registerCalibration(const std::string &camera, const unsigned int width, const unsigned int height, const Scalar fovX)
Registers a new camera calibration.
DeviceMap deviceMap_
Map holding all registered devices.
Definition CameraCalibrationManager.h:198
Lock lock_
The lock of this manager.
Definition CameraCalibrationManager.h:204
std::map< std::string, std::string > AliasMap
Definition of a map mapping alias device names to device names.
Definition CameraCalibrationManager.h:126
CameraCalibrationManager()
Creates a new manager.
bool registerCalibrationFile(const std::string &url)
Registers a new camera calibration file.
Priority
Definition of different priority values for the camera calibrations.
Definition CameraCalibrationManager.h:40
@ PRIORITY_LOW
Low priority.
Definition CameraCalibrationManager.h:42
@ PRIORITY_MEDIUM
Medium priority.
Definition CameraCalibrationManager.h:44
@ PRIORITY_HIGH
High priority.
Definition CameraCalibrationManager.h:46
std::map< std::string, Device > DeviceMap
Definition of a map mapping device names to device objects.
Definition CameraCalibrationManager.h:121
PinholeCamera camera(const std::string &device, const unsigned int width, const unsigned int height, Quality *quality=nullptr, const Scalar defaultFovX=Numeric::deg2rad(45)) const
Returns a calibration for a specific device with a specific frame resolution.
Quality
Definition of different calibration qualities.
Definition CameraCalibrationManager.h:55
@ QUALITY_INTERPOLATED
Interpolated calibration.
Definition CameraCalibrationManager.h:59
@ QUALITY_EXACT
Exact calibration.
Definition CameraCalibrationManager.h:57
This class implements a recursive lock object.
Definition Lock.h:31
This template class is the base class for all singleton objects.
Definition Singleton.h:71
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15