Ocean
ImageSequenceStereoImageProvider.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_MEDIA_IMAGE_SEQUENCE_STEREO_IMAGE_PROVIDER_H
9 #define META_OCEAN_MEDIA_IMAGE_SEQUENCE_STEREO_IMAGE_PROVIDER_H
10 
11 #include "ocean/media/Media.h"
14 
15 #include "ocean/math/SampleMap.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Media
21 {
22 
23 /**
24  * This class implements a provider for stereo images which are extracted from two separate image sequences and poses/calibration file.
25  * @ingroup media
26  */
28 {
29  public:
30 
31  /**
32  * Definition of a sample map holding 6-DOF transformations.
33  */
35 
36  public:
37 
38  /**
39  * Creates an invalid provider object.
40  */
42 
43  /**
44  * Move constructor.
45  * @param provider The provider to be moved
46  */
48 
49  /**
50  * Creates a provider object for two image sequences and a poses/calibration file.
51  * @param imageSequenceFilenameA The filename of the first image of the first image sequence (the image sequence of the first fisheye camera), must be valid
52  * @param imageSequenceFilenameB The filename of the first image of the second image sequence (the image sequence of the second fisheye camera), must be valid
53  * @param transformationsFilename The filename of the file containing the camera calibration of both fisheye cameras followed by the individual camera transformations
54  * @param framesPerSecond The number of frames per second, with range (0, infinity)
55  */
56  ImageSequenceStereoImageProvider(const std::string& imageSequenceFilenameA, const std::string& imageSequenceFilenameB, const std::string& transformationsFilename, const double framesPerSecond = 30.0);
57 
58  /**
59  * Returns the next stereo images from the provider, further optional transformations between device and world, and between cameras and device will be provided.
60  * @see StereoImageProviderInterface::nextStereoImages(), hasDeviceTransformations(), hasCameraTransformations().
61  */
62  bool nextStereoImages(FisheyeCamera& fisheyeCameraA, FisheyeCamera& fisheyeCameraB, Frame& imageA, Frame& imageB, HomogenousMatrixD4* world_T_device = nullptr, HomogenousMatrixD4* device_T_cameraA = nullptr, HomogenousMatrixD4* device_T_cameraB = nullptr, HomogenousMatricesD4* world_T_leftHandJoints = nullptr, HomogenousMatricesD4* world_T_rightHandJoints = nullptr, bool* abort = nullptr) override;
63 
64  /**
65  * Restarts with the first pair of stereo images.
66  * @return True, if succeeded
67  */
68  bool restart() override;
69 
70  /**
71  * Returns whether the provider has access to the transformations between device and world (world_T_device).
72  * @return True, if so
73  */
74  bool hasDeviceTransformations() const override;
75 
76  /**
77  * Returns whether the provider has access to the transformations between cameras and device (device_T_cameraA and device_T_cameraB).
78  * @return True, if so
79  */
80  bool hasCameraTransformations() const override;
81 
82  /**
83  * Returns whether this provider can provide valid stereo images (e.g., whether the underlying resources are initialized and whether the source exists).
84  * @return True, if so
85  */
86  bool isValid() const override;
87 
88  /**
89  * Releases all owned resources like e.g., the image sequence objects.
90  */
91  void release() override;
92 
93  /**
94  * Move operator.
95  * @param provider The provider to be moved
96  * @return Reference to this object
97  */
99 
100  /**
101  * Extracts the camera calibrations, the device transformations, and the camera transformations from a transformations file.
102  *
103  * The expected format can be outline as follows:
104  *
105  * ```
106  * intrinsics of camera A
107  * intrinsics of camera B
108  * frame 1: world_T_device device_T_cameraA device_T_cameraB
109  * frame 2: world_T_device device_T_cameraA device_T_cameraB
110  * frame 3: world_T_device device_T_cameraA device_T_cameraB
111  * ...
112  * ```
113  *
114  * or, more verbosely,
115  *
116  * ```
117  * widthA heightA focalLengthXA focalLengthYA principalPointXA principalPointYA radialDistortionA[0] radialDistortionA[1] radialDistortionA[2] radialDistortionA[3] radialDistortionA[4] radialDistortionA[5] tangentialDistortionA[0] tangentialDistortionA[1]
118  * widthB heightB focalLengthXB focalLengthYB principalPointXB principalPointYB radialDistortionB[0] radialDistortionB[1] radialDistortionB[2] radialDistortionB[3] radialDistortionB[4] radialDistortionB[5] tangentialDistortionB[0] tangentialDistortionB[1]
119  * [wTd0] [wTd1] [wTd2] [wTd3] [wTd4] [wTd5] [wTd6] [wTd7] [wTd8] [wTd9] [wTd10] [wTd11] [wTd12] [wTd13] [wTd14] [wTd15] [dTa0] [dTa1] [dTa2] [dTa3] [dTa4] [dTa5] [dTa6] [dTa7] [dTa8] [dTa9] [dTa10] [dTa11] [dTa12] [dTa13] [dTa14] [dTa15] [dTb0] [dTb1] [dTb2] [dTb3] [dTb4] [dTb5] [dTb6] [dTb7] [dTb8] [dTb9] [dTb10] [dTb11] [dTb12] [dTb13] [dTb14] [dTb15]
120  * [wTd0] [wTd1] [wTd2] [wTd3] [wTd4] [wTd5] [wTd6] [wTd7] [wTd8] [wTd9] [wTd10] [wTd11] [wTd12] [wTd13] [wTd14] [wTd15] [dTa0] [dTa1] [dTa2] [dTa3] [dTa4] [dTa5] [dTa6] [dTa7] [dTa8] [dTa9] [dTa10] [dTa11] [dTa12] [dTa13] [dTa14] [dTa15] [dTb0] [dTb1] [dTb2] [dTb3] [dTb4] [dTb5] [dTb6] [dTb7] [dTb8] [dTb9] [dTb10] [dTb11] [dTb12] [dTb13] [dTb14] [dTb15]
121  * [wTd0] [wTd1] [wTd2] [wTd3] [wTd4] [wTd5] [wTd6] [wTd7] [wTd8] [wTd9] [wTd10] [wTd11] [wTd12] [wTd13] [wTd14] [wTd15] [dTa0] [dTa1] [dTa2] [dTa3] [dTa4] [dTa5] [dTa6] [dTa7] [dTa8] [dTa9] [dTa10] [dTa11] [dTa12] [dTa13] [dTa14] [dTa15] [dTb0] [dTb1] [dTb2] [dTb3] [dTb4] [dTb5] [dTb6] [dTb7] [dTb8] [dTb9] [dTb10] [dTb11] [dTb12] [dTb13] [dTb14] [dTb15]
122  * ...
123  * ```
124  *
125  * where the first two rows contain the intrinsics of the two fisheye cameras, and starting with the third row each row
126  * stores three homogeneous 4-by-4 matrices which correspond to one frame. The matrix elements of each transformation are
127  * stored in column-major order, i.e.,
128  *
129  * ```
130  * m = [m0 m4 m8 m12]
131  * [m1 m5 m9 m13]
132  * [m2 m6 m10 m14]
133  * [m3 m7 m11 m15]
134  * ```
135  *
136  * @param transformationsFilename The filename of the transformations file, must be valid
137  * @param fisheyeCameraA The resulting profile of the first fisheye camera
138  * @param fisheyeCameraB The resulting profile of the second fisheye camera
139  * @param map_world_T_device The resulting sample map transforming device to world
140  * @param map_device_T_cameraA The resulting sample map transforming the first camera to device
141  * @param map_device_T_cameraB The resulting sample map transforming the second camera to device
142  * @param framesPerSecond The number of frames per second, with range (0, infinity)
143  * @return True, if succeeded
144  */
145  static bool readTransformationsFile(const std::string& transformationsFilename, FisheyeCamera& fisheyeCameraA, FisheyeCamera& fisheyeCameraB, TransformationMap& map_world_T_device, TransformationMap& map_device_T_cameraA, TransformationMap& map_device_T_cameraB, const double framesPerSecond = 30.0);
146 
147  protected:
148 
149  /**
150  * Disabled copy constructor.
151  * @param provider The provider which would have been copied
152  */
154 
155  /**
156  * Disabled assign operator.
157  * @param provider The provider which would have been assigned
158  * @return Reference to this object
159  */
161 
162  protected:
163 
164  /// The first image sequence providing the images for the first stereo camera.
166 
167  /// The second image sequence providing the images for the first stereo camera.
169 
170  /// The fisheye camera profile of the first camera.
172 
173  /// The fisheye camera profile of the second camera.
175 
176  /// The sample map transforming device to world.
178 
179  /// The sample map transforming the first camera to device.
181 
182  /// The sample map transforming the second camera to device.
184 
185  /// The number of frames per second, with range (0, infinity)
187 };
188 
189 }
190 
191 }
192 
193 #endif // META_OCEAN_MEDIA_IMAGE_SEQUENCE_STEREO_IMAGE_PROVIDER_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a provider for stereo images which are extracted from two separate image sequen...
Definition: ImageSequenceStereoImageProvider.h:28
ImageSequenceRef imageSequenceA_
The first image sequence providing the images for the first stereo camera.
Definition: ImageSequenceStereoImageProvider.h:165
static bool readTransformationsFile(const std::string &transformationsFilename, FisheyeCamera &fisheyeCameraA, FisheyeCamera &fisheyeCameraB, TransformationMap &map_world_T_device, TransformationMap &map_device_T_cameraA, TransformationMap &map_device_T_cameraB, const double framesPerSecond=30.0)
Extracts the camera calibrations, the device transformations, and the camera transformations from a t...
bool restart() override
Restarts with the first pair of stereo images.
ImageSequenceStereoImageProvider(ImageSequenceStereoImageProvider &&provider)
Move constructor.
bool isValid() const override
Returns whether this provider can provide valid stereo images (e.g., whether the underlying resources...
TransformationMap map_world_T_device_
The sample map transforming device to world.
Definition: ImageSequenceStereoImageProvider.h:177
FisheyeCamera fisheyeCameraB_
The fisheye camera profile of the second camera.
Definition: ImageSequenceStereoImageProvider.h:174
TransformationMap map_device_T_cameraB_
The sample map transforming the second camera to device.
Definition: ImageSequenceStereoImageProvider.h:183
FisheyeCamera fisheyeCameraA_
The fisheye camera profile of the first camera.
Definition: ImageSequenceStereoImageProvider.h:171
double framesPerSecond_
The number of frames per second, with range (0, infinity)
Definition: ImageSequenceStereoImageProvider.h:186
ImageSequenceRef imageSequenceB_
The second image sequence providing the images for the first stereo camera.
Definition: ImageSequenceStereoImageProvider.h:168
bool hasDeviceTransformations() const override
Returns whether the provider has access to the transformations between device and world (world_T_devi...
SampleMap< HomogenousMatrixD4 > TransformationMap
Definition of a sample map holding 6-DOF transformations.
Definition: ImageSequenceStereoImageProvider.h:34
TransformationMap map_device_T_cameraA_
The sample map transforming the first camera to device.
Definition: ImageSequenceStereoImageProvider.h:180
ImageSequenceStereoImageProvider & operator=(ImageSequenceStereoImageProvider &&provider)
Move operator.
void release() override
Releases all owned resources like e.g., the image sequence objects.
ImageSequenceStereoImageProvider & operator=(const ImageSequenceStereoImageProvider &provider)=delete
Disabled assign operator.
ImageSequenceStereoImageProvider()
Creates an invalid provider object.
ImageSequenceStereoImageProvider(const ImageSequenceStereoImageProvider &provider)=delete
Disabled copy constructor.
bool hasCameraTransformations() const override
Returns whether the provider has access to the transformations between cameras and device (device_T_c...
ImageSequenceStereoImageProvider(const std::string &imageSequenceFilenameA, const std::string &imageSequenceFilenameB, const std::string &transformationsFilename, const double framesPerSecond=30.0)
Creates a provider object for two image sequences and a poses/calibration file.
bool nextStereoImages(FisheyeCamera &fisheyeCameraA, FisheyeCamera &fisheyeCameraB, Frame &imageA, Frame &imageB, HomogenousMatrixD4 *world_T_device=nullptr, HomogenousMatrixD4 *device_T_cameraA=nullptr, HomogenousMatrixD4 *device_T_cameraB=nullptr, HomogenousMatricesD4 *world_T_leftHandJoints=nullptr, HomogenousMatricesD4 *world_T_rightHandJoints=nullptr, bool *abort=nullptr) override
Returns the next stereo images from the provider, further optional transformations between device and...
This class is the abstract base class for all stereo image providers.
Definition: StereoImageProviderInterface.h:31
std::vector< HomogenousMatrixD4 > HomogenousMatricesD4
Definition of a vector holding HomogenousMatrixD4 objects.
Definition: HomogenousMatrix4.h:79
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15