Ocean
TestFrameRectification.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_TEST_TESTCV_TESTADVANCED_TEST_FRAME_RECTIFICATION_H
9 #define META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_FRAME_RECTIFICATION_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
16 #include "ocean/math/AnyCamera.h"
17 #include "ocean/math/Box3.h"
19 #include "ocean/math/Vector2.h"
20 
21 namespace Ocean
22 {
23 
24 namespace Test
25 {
26 
27 namespace TestCV
28 {
29 
30 namespace TestAdvanced
31 {
32 
33 /**
34  * This class implements a frame rectification test.
35  * @ingroup testcvadvanced
36  */
37 class OCEAN_TEST_CV_ADVANCED_EXPORT TestFrameRectification
38 {
39  public:
40 
41  /**
42  * Tests the frame rectification functions.
43  * @param width The width of the test frame in pixel, with range [1u, infinity)
44  * @param height The height of the test frame in pixel, with range [1, infinity)
45  * @param testDuration The number of seconds for each test, with range (0, infinity)
46  * @param worker The worker object to distribute the computation
47  * @return True, if succeeded
48  */
49  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
50 
51  /**
52  * Tests the rectification function for a planar rectangle object.
53  * @param width The width of the test frame in pixel, with range [1u, infinity)
54  * @param height The height of the test frame in pixel, with range [1, infinity)
55  * @param testDuration The number of seconds for each test, with range (0, infinity)
56  * @param worker The worker object to distribute the computation
57  * @return True, if succeeded
58  */
59  static bool testPlanarRectangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
60 
61  /**
62  * Tests the rectification function for an arbitrary rectangle object.
63  * @param width The width of the test frame in pixel, with range [1u, infinity)
64  * @param height The height of the test frame in pixel, with range [1, infinity)
65  * @param testDuration The number of seconds for each test, with range (0, infinity)
66  * @param worker The worker object to distribute the computation
67  * @return True, if succeeded
68  */
69  static bool testArbitraryRectangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
70 
71  /**
72  * Tests the rectification function for triangles.
73  * @param width The width of the test frame in pixel, with range [1u, infinity)
74  * @param height The height of the test frame in pixel, with range [1, infinity)
75  * @param testDuration The number of seconds for each test, with range (0, infinity)
76  * @param worker The worker object to distribute the computation
77  * @return True, if succeeded
78  */
79  static bool testTriangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
80 
81  /**
82  * Tests the mask rectification function for a planar rectangle object.
83  * @param width The width of the test frame in pixel, with range [1u, infinity)
84  * @param height The height of the test frame in pixel, with range [1, infinity)
85  * @param testDuration The number of seconds for each test, with range (0, infinity)
86  * @param worker The worker object to distribute the computation
87  * @return True, if succeeded
88  */
89  static bool testPlanarRectangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
90 
91  /**
92  * Tests the mask rectification function for an arbitrary rectangle object.
93  * @param width The width of the test frame in pixel, with range [1u, infinity)
94  * @param height The height of the test frame in pixel, with range [1, infinity)
95  * @param testDuration The number of seconds for each test, with range (0, infinity)
96  * @param worker The worker object to distribute the computation
97  * @return True, if succeeded
98  */
99  static bool testArbitraryRectangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
100 
101  /**
102  * Tests the mask rectification function for triangles.
103  * @param width The width of the test frame in pixel, with range [1u, infinity)
104  * @param height The height of the test frame in pixel, with range [1, infinity)
105  * @param testDuration The number of seconds for each test, with range (0, infinity)
106  * @param worker The worker object to distribute the computation
107  * @return True, if succeeded
108  */
109  static bool testTriangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
110 
111  protected:
112 
113  /**
114  * Determines the average color intensity error between two frames while excluding a two pixel thick border at the frame boundaries.
115  * @param frame0 The first frame to be checked, must be valid
116  * @param frame1 The second frame to be checked, must be valid
117  * @param skipColor0 Optional pixel color to skip error calculation for pixels with this color in the first frame, nullptr otherwise
118  * @param skipColor1 Optional pixel color to skip error calculation for pixels with this color in the second frame, nullptr otherwise
119  * @return The average pixel-wise color difference between both frame
120  */
121  static double determineFrameError(const Frame& frame0, const Frame& frame1, const uint8_t* skipColor0, const uint8_t* skipColor1);
122 
123  /**
124  * Renders a planar rectangular object with given camera profile and camera pose.
125  * @param objectFrame The square object frame to be rendered, must be valid
126  * @param targetFrame The resulting rendered frame, must be valid
127  * @param camera The camera profile to be used for rendering
128  * @param world_T_camera The transformation between camera and world, must be valid
129  * @param objectDimension The dimension of the object frame to be rendered, with range (0, infinity)x(0, infinity)
130  * @return True, if succeeded
131  */
132  static bool renderPlanarRectangleObject(const Frame& objectFrame, Frame& targetFrame, const AnyCamera& camera, const HomogenousMatrix4& world_T_camera, const Vector2& objectDimension);
133 
134  /**
135  * Determines a camera pose so that all corners of a given bounding box are visible in the camera.
136  * @param camera The camera profile defining the projection, must be valid
137  * @param boundingBox The 3D bounding box, must be valid
138  * @param world_R_camera The rotation of the camera to be used, must be valid
139  * @return The transformation between camera and world (world_T_camera)
140  */
141  static HomogenousMatrix4 determineCameraPose(const AnyCamera& camera, const Box3& boundingBox, const Quaternion& world_R_camera);
142 };
143 
144 }
145 
146 }
147 
148 }
149 
150 }
151 
152 #endif // META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_FRAME_RECTIFICATION_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a frame rectification test.
Definition: TestFrameRectification.h:38
static bool renderPlanarRectangleObject(const Frame &objectFrame, Frame &targetFrame, const AnyCamera &camera, const HomogenousMatrix4 &world_T_camera, const Vector2 &objectDimension)
Renders a planar rectangular object with given camera profile and camera pose.
static bool testArbitraryRectangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the rectification function for an arbitrary rectangle object.
static bool testTriangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the rectification function for triangles.
static HomogenousMatrix4 determineCameraPose(const AnyCamera &camera, const Box3 &boundingBox, const Quaternion &world_R_camera)
Determines a camera pose so that all corners of a given bounding box are visible in the camera.
static double determineFrameError(const Frame &frame0, const Frame &frame1, const uint8_t *skipColor0, const uint8_t *skipColor1)
Determines the average color intensity error between two frames while excluding a two pixel thick bor...
static bool testPlanarRectangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the mask rectification function for a planar rectangle object.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the frame rectification functions.
static bool testPlanarRectangleObject(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the rectification function for a planar rectangle object.
static bool testTriangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the mask rectification function for triangles.
static bool testArbitraryRectangleObjectMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the mask rectification function for an arbitrary rectangle object.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15