Ocean
Loading...
Searching...
No Matches
TestFramePyramid.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_TEST_FRAME_PYRAMID_H
9#define META_OCEAN_TEST_TESTCV_TEST_FRAME_PYRAMID_H
10
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Worker.h"
15
17
19
20namespace Ocean
21{
22
23namespace Test
24{
25
26namespace TestCV
27{
28
29/**
30 * This class implements tests for the functionality of frame pyramids.
31 * @see Ocean::CV::FramePyramid
32 * @ingroup testcv
33 */
34class OCEAN_TEST_CV_EXPORT TestFramePyramid : protected CV::FramePyramid
35{
36 protected:
37
38 /**
39 * Default value to create as many layers as possible.
40 */
41 static constexpr unsigned int ALL_LAYERS = (unsigned int)(-1);
42
43 public:
44
45 /**
46 * Tests the functionality of frame pyramids
47 * @param testDuration Number of seconds for each test
48 * @param worker The worker object to distribute the computational load
49 * @param selector The test selector to control which tests to run
50 * @return True, if succeeded
51 */
52 static bool test(const double testDuration, Worker& worker, const TestSelector& selector = TestSelector());
53
54 /**
55 * Tests the ideal layers functions.
56 * @param testDuration Number of seconds for each test
57 * @return True, if succeeded
58 */
59 static bool testIdealLayers(const double testDuration);
60
61 /**
62 * Tests the ideal coarsest layer radius function.
63 * @param testDuration Number of seconds for each test
64 * @return True, if succeeded
65 */
66 static bool testIdealCoarsestLayerRadius(const double testDuration);
67
68 /**
69 * Tests the ideal tracking parameters function.
70 * @param testDuration Number of seconds for each test
71 * @return True, if succeeded
72 */
73 static bool testIdealTrackingParameters(const double testDuration);
74
75 /**
76 * Tests the isOwner() function.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testIsOwner(const double testDuration);
81
82 /**
83 * Tests the calculateMemorySize() function.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 */
87 static bool testCalculateMemorySize(const double testDuration);
88
89 /**
90 * Tests the creation of a frame pyramid using the constructor.
91 * @param testDuration Number of seconds for each test, with range (0, infinity)
92 * @param worker The worker object to distribute the computation
93 * @return True, if succeeded
94 */
95 static bool testCreationFramePyramidWithConstructor(const double testDuration, Worker& worker);
96
97 /**
98 * Tests the creation of a frame pyramid using the constructor for a specific frame with specific number of resulting layers.
99 * @param width The width of the test frame in pixel, width range [1, infinity)
100 * @param height The width of the test frame in pixel, height range [1, infinity)
101 * @param channels The width of the test frame in pixel, channels range [1, infinity)
102 * @param layers The number of pyramid layers to be created, with range [1, infinity)
103 * @param testDuration Number of seconds for each test, with range (0, infinity)
104 * @param worker The worker object to distribute the computation
105 * @return True, if succeeded
106 */
107 static bool testCreationFramePyramidWithConstructor(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker& worker);
108
109 /**
110 * Tests the creation of a frame pyramid using the replace() function.
111 * @param testDuration Number of seconds for each test, with range (0, infinity)
112 * @param worker The worker object to distribute the computation
113 * @return True, if succeeded
114 */
115 static bool testCreationFramePyramidWithReplace(const double testDuration, Worker& worker);
116
117 /**
118 * Tests the creation of a frame pyramid using the replace() function for a specific frame with specific number of resulting layers.
119 * @param width The width of the test frame in pixel, width range [1, infinity)
120 * @param height The width of the test frame in pixel, height range [1, infinity)
121 * @param channels The width of the test frame in pixel, channels range [1, infinity)
122 * @param layers The number of pyramid layers to be created, with range [1, infinity)
123 * @param testDuration Number of seconds for each test, with range (0, infinity)
124 * @param worker The worker object to distribute the computation
125 * @return True, if succeeded
126 */
127 static bool testCreationFramePyramidWithReplace(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker& worker);
128
129 /**
130 * Tests the creation of a frame pyramid with extreme parameters.
131 * @return True, if the test succeeded; otherwise, false is returned.
132 */
134
135 /**
136 * Tests the construction of a new frame pyramid from an existing frame.
137 * @param testDuration Requested duration of test loop in seconds
138 * @param worker Optional worker instance
139 * @return True, if the test succeeded; otherwise, false is returned
140 */
141 static bool testConstructFromFrameMultiLayer(const double testDuration, Worker& worker);
142
143 /**
144 * Tests the construction of a new frame pyramid from an existing frame.
145 * @param width The width of the source image in pixel, with range [1, infinity)
146 * @param height The height of the source image in pixel, with range [1, infinity)
147 * @param layerCount Number of layers to create, with range [1, infinity)
148 * @param testDuration Requested duration of test loop in seconds
149 * @param worker The worker object to distribute the computation
150 * @return True, if the test succeeded; otherwise, false is returned
151 */
152 static bool testConstructFromFrameMultiLayer(const unsigned int width, const unsigned int height, const unsigned int layerCount, const double testDuration, Worker& worker);
153
154 /**
155 * Tests the construction of a new frame pyramid from an existing source pyramid.
156 * @param testDuration Requested duration of test loop in seconds
157 * @param worker The worker object to distribute the computation
158 * @return True, if the test succeeded; otherwise, false is returned.
159 */
160 static bool testConstructFromPyramid(const double testDuration, Worker& worker);
161
162 /**
163 * Tests the replacement of a frame pyramid using a frame type.
164 * @param testDuration Requested duration of test loop in seconds
165 * @return True, if the test succeeded; otherwise, false is returned.
166 */
167 static bool testReplaceWithFrameType(const double testDuration);
168
169 /**
170 * Tests the replacement of a frame pyramid using a frame type.
171 * @param testDuration Requested duration of test loop in seconds
172 * @param worker The worker object to distribute the computation
173 * @return True, if the test succeeded; otherwise, false is returned.
174 */
175 static bool testReplaceWithFrame(const double testDuration, Worker& worker);
176
177 /**
178 * Tests the replacement of a frame pyramid using a 1-1 downsampling.
179 * @param testDuration Requested duration of test loop in seconds
180 * @param worker The worker object to distribute the computation
181 * @return True, if the test succeeded; otherwise, false is returned.
182 */
183 static bool testReplace11(const double testDuration, Worker& worker);
184
185 /**
186 * Tests the constructor of a frame pyramid using a 1-1 downsampling.
187 * @param testDuration Requested duration of test loop in seconds
188 * @param worker The worker object to distribute the computation
189 * @return True, if the test succeeded; otherwise, false is returned.
190 */
191 static bool testConstructor11(const double testDuration, Worker& worker);
192
193 /**
194 * Tests the reduceLayers() function.
195 * @param testDuration Number of seconds for each test, with range (0, infinity)
196 * @return True, if succeeded
197 */
198 static bool testReduceLayers(const double testDuration);
199
200 protected:
201
202 /**
203 * Validates the visual content of a frame pyramid.
204 * @param frame The frame from which the frame pyramid has been created, must be valid
205 * @param framePyramid The frame pyramid to be validated, must be valid
206 * @param downsamplingMode The downsampling mode that has been applied when creating the pyramid, either DM_FILTER_11 or DM_FILTER_14641
207 * @param layers The explicit number of pyramid layers to be checked, with range [1, infinity)
208 * @param allowCompatibleFrameType True, to allow a compatible frame type; False, to expect a perfectly matching frame type
209 * @return True, if succeeded
210 */
211 static bool validateFramePyramid(const Frame& frame, const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const unsigned int layers, const bool allowCompatibleFrameType = false);
212
213 /**
214 * Validates the visual content of a frame pyramid.
215 * @param frame The frame from which the frame pyramid has been created, must be valid
216 * @param framePyramid The frame pyramid to be validated, must be valid
217 * @param downsamplingFunction The function which has been used to downsample the pyramid layers, must be valid
218 * @param layers The explicit number of pyramid layers to be checked, with range [1, infinity)
219 * @param allowCompatibleFrameType True, to allow a compatible frame type; False, to expect a perfectly matching frame type
220 * @return True, if succeeded
221 */
222 static bool validateFramePyramid(const Frame& frame, const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool allowCompatibleFrameType = false);
223
224 /**
225 * Validates if the frame pyramid was created correctly with the specified settings.
226 * @param framePyramid The frame pyramid to validate, must be valid
227 * @param downsamplingMode The downsampling mode that has been applied when creating the pyramid, either DM_FILTER_11 or DM_FILTER_14641
228 * @param frame The frame that was used to create the frame pyramid, must be valid
229 * @param numberLayers The number of layers the pyramid needs to have, with range [1, infinity)
230 * @param readOnlyLayers The indices of all layers which are expected to be read-only, all other layers are expected to be writable
231 * @param ownerLayers The indices of all layers which are expected to own the memory
232 * @param outsideMemoryBlockLayers The indices of all layers which are expected to have their memory outside of the pyramid's memory block
233 * @return True, if the pyramid is correct
234 */
235 static bool validateConstructFromFrame(const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const Frame& frame, const unsigned int numberLayers, const UnorderedIndexSet32& readOnlyLayers, const UnorderedIndexSet32& ownerLayers, const UnorderedIndexSet32& outsideMemoryBlockLayers);
236
237 /**
238 * Validates if the frame pyramid was created correctly with the specified settings.
239 * @param framePyramid The frame pyramid to validate, must be valid
240 * @param downsamplingFunction The function which has been used to downsample the pyramid layers, must be valid
241 * @param frame The frame that was used to create the frame pyramid, must be valid
242 * @param numberLayers The number of layers the pyramid needs to have, with range [1, infinity)
243 * @param readOnlyLayers The indices of all layers which are expected to be read-only, all other layers are expected to be writable
244 * @param ownerLayers The indices of all layers which are expected to own the memory
245 * @param outsideMemoryBlockLayers The indices of all layers which are expected to have their memory outside of the pyramid's memory block
246 * @return True, if the pyramid is correct
247 */
248 static bool validateConstructFromFrame(const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingFunction& downsamplingFunction, const Frame& frame, const unsigned int numberLayers, const UnorderedIndexSet32& readOnlyLayers, const UnorderedIndexSet32& ownerLayers, const UnorderedIndexSet32& outsideMemoryBlockLayers);
249
250 /**
251 * Returns the maximum layer count for the given frame width and height
252 * @param width Frame width in pixel
253 * @param height Frame height in pixel
254 * @return The maximum number of pyramid layers that can be generate for this frame
255 */
256 static unsigned int determineMaxLayerCount(unsigned int width, unsigned int height);
257
258 /**
259 * Verifies the ownership properties of a frame pyramid.
260 * @param framePyramid The frame pyramid to verify, can be invalid
261 * @param isValid True, if the frame pyramid is expected to be valid
262 * @param isOwner True, if the entire frame pyramid is expected to own the memory of all pyramid layers; False, if at least one layer is not owned
263 * @param layerIsOwner The explicit indices of all pyramid layers for which the pyramid is owning the memory, all other layers don't own the memory, empty to skip this check
264 * @return True, if all properties match
265 */
266 static bool verifyPyramidOwnership(const CV::FramePyramid& framePyramid, const bool isValid, const bool isOwner, const Indices32& layerIsOwner = Indices32());
267};
268
269}
270
271}
272
273}
274
275#endif // META_OCEAN_TEST_TESTCV_TEST_FRAME_PYRAMID_H
This class implements a frame pyramid.
Definition FramePyramid.h:46
std::function< bool(const Frame &sourceLayer, Frame &targetLayer, Worker *worker)> DownsamplingFunction
Definition of a function allowing to downsample a frame.
Definition FramePyramid.h:91
DownsamplingMode
Definition of individual down sampling modes.
Definition FramePyramid.h:53
This class implements Ocean's image class.
Definition Frame.h:1879
This class implements tests for the functionality of frame pyramids.
Definition TestFramePyramid.h:35
static bool testIdealTrackingParameters(const double testDuration)
Tests the ideal tracking parameters function.
static bool testConstructor11(const double testDuration, Worker &worker)
Tests the constructor of a frame pyramid using a 1-1 downsampling.
static bool testCreationFramePyramidWithConstructor(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the constructor for a specific frame with specific number...
static bool testCalculateMemorySize(const double testDuration)
Tests the calculateMemorySize() function.
static bool testConstructFromFrameMultiLayer(const unsigned int width, const unsigned int height, const unsigned int layerCount, const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing frame.
static bool testConstructFromPyramid(const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing source pyramid.
static bool validateConstructFromFrame(const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const Frame &frame, const unsigned int numberLayers, const UnorderedIndexSet32 &readOnlyLayers, const UnorderedIndexSet32 &ownerLayers, const UnorderedIndexSet32 &outsideMemoryBlockLayers)
Validates if the frame pyramid was created correctly with the specified settings.
static bool testIdealCoarsestLayerRadius(const double testDuration)
Tests the ideal coarsest layer radius function.
static bool verifyPyramidOwnership(const CV::FramePyramid &framePyramid, const bool isValid, const bool isOwner, const Indices32 &layerIsOwner=Indices32())
Verifies the ownership properties of a frame pyramid.
static bool test(const double testDuration, Worker &worker, const TestSelector &selector=TestSelector())
Tests the functionality of frame pyramids.
static bool testCreationFramePyramidWithConstructor(const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the constructor.
static bool testCreationFramePyramidWithReplace(const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the replace() function.
static bool validateFramePyramid(const Frame &frame, const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const unsigned int layers, const bool allowCompatibleFrameType=false)
Validates the visual content of a frame pyramid.
static bool testReplace11(const double testDuration, Worker &worker)
Tests the replacement of a frame pyramid using a 1-1 downsampling.
static bool validateConstructFromFrame(const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingFunction &downsamplingFunction, const Frame &frame, const unsigned int numberLayers, const UnorderedIndexSet32 &readOnlyLayers, const UnorderedIndexSet32 &ownerLayers, const UnorderedIndexSet32 &outsideMemoryBlockLayers)
Validates if the frame pyramid was created correctly with the specified settings.
static bool testReplaceWithFrameType(const double testDuration)
Tests the replacement of a frame pyramid using a frame type.
static bool testIsOwner(const double testDuration)
Tests the isOwner() function.
static bool testIdealLayers(const double testDuration)
Tests the ideal layers functions.
static unsigned int determineMaxLayerCount(unsigned int width, unsigned int height)
Returns the maximum layer count for the given frame width and height.
static bool testConstructFromFrameMultiLayer(const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing frame.
static bool testReduceLayers(const double testDuration)
Tests the reduceLayers() function.
static bool testCreateFramePyramidExtreme()
Tests the creation of a frame pyramid with extreme parameters.
static bool testReplaceWithFrame(const double testDuration, Worker &worker)
Tests the replacement of a frame pyramid using a frame type.
static bool testCreationFramePyramidWithReplace(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the replace() function for a specific frame with specific...
static bool validateFramePyramid(const Frame &frame, const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingFunction &downsamplingFunction, const unsigned int layers, const bool allowCompatibleFrameType=false)
Validates the visual content of a frame pyramid.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition Base.h:126
The namespace covering the entire Ocean framework.
Definition Accessor.h:15