Ocean
Loading...
Searching...
No Matches
FramePyramid.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_CV_FRAME_PYRAMID_H
9#define META_OCEAN_CV_FRAME_PYRAMID_H
10
11#include "ocean/cv/CV.h"
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Memory.h"
15#include "ocean/base/Worker.h"
16
19
20#include <functional>
21
22namespace Ocean
23{
24
25namespace CV
26{
27
28// Forward declaration.
29class FramePyramid;
30
31/**
32 * Definition of a vector holding frame pyramid objects.
33 * @see FramePyramid
34 * @ingroup cv
35 */
36using FramePyramids = std::vector<FramePyramid>;
37
38/**
39 * This class implements a frame pyramid.<br>
40 * A frame pyramid holds the same frame with several scale spaces.<br>
41 * Each further layer holds the frame with half size (half width and half height).<br>
42 * The finest layer has index 0 and the coarsest layer has the highest index.
43 * @ingroup cv
44 */
45class OCEAN_CV_EXPORT FramePyramid
46{
47 public:
48
49 /**
50 * Definition of individual down sampling modes.
51 */
52 enum DownsamplingMode : uint32_t
53 {
54 /**
55 * Down sampling is realized by a 2x2 averaging filter.
56 * This down sampling mode is the fastest mode available, as 2x2 pixel blocks are simply averaged.<br>
57 * The corresponding filter mask has the following layout:
58 * <pre>
59 * | 1 1 |
60 * | 1 1 | * 1/4
61 * </pre>
62 * The upper left filter element is applied to every even pixel location in the source frame.<br>
63 * In case, the width or height of a given frame is odd, the last column/row will apply a 121 filter.
64 */
66
67 /**
68 * Down sampling is realized by a 5x5 Gaussian filter.
69 * This down sampling mode is more expensive but reduces aliasing effects on down sampled images.<br>
70 * The corresponding filter mask has the following layout:
71 * <pre>
72 * | 1 4 6 4 1 |
73 * | 4 16 24 16 4 |
74 * | 6 24 36 24 6 | * 1/256
75 * | 4 16 24 16 4 |
76 * | 1 4 6 4 1 |
77 * </pre>
78 * The center of the filter is applied to every even pixel location in the source frame.<br>
79 * At the border of frames, the filter responses are determined based on mirrored pixel values.
80 */
81 DM_FILTER_14641
82 };
83
84 /**
85 * Definition of a function allowing to downsample a frame.
86 * @param sourceLayer The source layer to downsample
87 * @param targetLayer The target layer receiving the downsampled image content
88 * @param worker Optional worker to distribute the computation
89 * @return True, if succeeded
90 */
91 using DownsamplingFunction = std::function<bool(const Frame& sourceLayer, Frame& targetLayer, Worker* worker)>;
92
93 /**
94 * Definition of a value that can be used to create as many pyramid layers as possible (so that the coarsest pyramid layer has resolution 1x1).
95 */
96 static constexpr unsigned int AS_MANY_LAYERS_AS_POSSIBLE = (unsigned int)(-1);
97
98 protected:
99
100 /// The number of bytes for memory alignment.
101 static constexpr size_t memoryAlignmentBytes_ = 8;
102
103 public:
104
105 /**
106 * Creates an empty frame pyramid object.
107 */
108 inline FramePyramid();
109
110 /**
111 * Copy constructor.
112 * @param framePyramid Frame pyramid to be copied
113 * @param copyData True, to copy the image content of the frame pyramid; False, to only reuse the image content of the frame pyramid
114 */
115 FramePyramid(const FramePyramid& framePyramid, const bool copyData);
116
117 /**
118 * Move constructor.
119 * @param framePyramid Frame pyramid to be moved
120 */
121 FramePyramid(FramePyramid&& framePyramid) noexcept;
122
123 /**
124 * Creates a frame pyramid object for a given frame type and layer number.
125 * The resulting pyramid may have fewer layers than desired.<br>
126 * The image content of the replaced frame pyramid will be uninitialized.
127 * @param layers The preferred number of layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as may layers as possible
128 * @param frameType Type of the frame to create a frame pyramid for, must be valid
129 */
130 explicit FramePyramid(const unsigned int layers, const FrameType& frameType);
131
132 /**
133 * Creates a new pyramid frame for frames with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
134 * This constructor is intentionally restrictive to reduce binary impact when used, use other constructors or functions in case more flexibility is needed an binary size does not matter.<br>
135 * The constructor mainly calls replace8BitPerChannel11().
136 * @param frame The frame for which the pyramid will be created, must be valid
137 * @param width The width of the given frame in pixel, with range [1, infinity)
138 * @param height The height of the given frame in pixel, with range [1, infinity)
139 * @param channels The number of channels the given frame has, with range [1, infinity)
140 * @param pixelOrigin The pixel origin of the given frame
141 * @param layers Number of pyramid layers to be created, with range [1, infinity)
142 * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
143 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
144 * @param worker Optional worker object to distribute the computation
145 * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
146 * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
147 * @see replace8BitPerChannel11().
148 */
149 inline FramePyramid(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker = nullptr, const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED, const Timestamp timestamp = Timestamp(false));
150
151 /**
152 * Creates a new pyramid frame for frames with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
153 * This constructor is intentionally restrictive to reduce binary impact when used, use other constructors or functions in case more flexibility is needed an binary size does not matter.<br>
154 * In case the provided frame not a valid 1-plane DT_UNSIGNED_INTEGER_8 frame, the pyramid will be invalid.<br>
155 * The constructor mainly calls replace8BitPerChannel11().
156 * @param frame The frame for which the pyramid will be created, with 1 plane and data type DT_UNSIGNED_INTEGER_8, must be valid
157 * @param layers Number of pyramid layers to be created, with range [1, infinity)
158 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
159 * @param worker Optional worker object to distribute the computation
160 * @see replace8BitPerChannel11().
161 */
162 inline FramePyramid(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker = nullptr);
163
164 /**
165 * Creates a frame pyramid based on a frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a custom downsampling.
166 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.<br>
167 * The constructor mainly calls replace8BitPerChannel().
168 * @param frame The frame for which the pyramid will be created, must be valid
169 * @param width The width of the frame in pixel, with range [1, infinity)
170 * @param height The height of the frame in pixel, with range [1, infinity)
171 * @param channels The number of channels the given frame has, with range [1, infinity)
172 * @param pixelOrigin The pixel origin of the given frame
173 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
174 * @param layers Number of pyramid layers to be created, with range [1, infinity)
175 * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
176 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
177 * @param worker Optional worker object to distribute the computation
178 * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
179 * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
180 * @see replace8BitPerChannel().
181 */
182 inline FramePyramid(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const DownsamplingMode downsamplingMode, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker, const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED, const Timestamp timestamp = Timestamp(false));
183
184 /**
185 * Creates a frame pyramid based on a frame applying a custom downsampling.
186 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
187 * @param frame The frame for which the pyramid will be created, must be valid
188 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
189 * @param layers The number of pyramid layers to be created, with range [1, infinity)
190 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exists)
191 * @param worker Optional worker object to distribute the computation
192 */
193 inline FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
194
195 /**
196 * Creates a frame pyramid based on a frame applying a custom downsampling.
197 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
198 * @param frame The frame for which the pyramid will be created, must be valid
199 * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
200 * @param layers The number of pyramid layers to be created, with range [1, infinity)
201 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exists)
202 * @param worker Optional worker object to distribute the computation
203 */
204 inline FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
205
206 /**
207 * Creates a frame pyramid based on a frame applying a custom downsampling.
208 * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
209 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
210 * @param frame The frame for which the pyramid will be created, must be valid
211 * @param layers The number of pyramid layers to be created, with range [1, infinity)
212 * @param worker Optional worker object to distribute the computation
213 */
214 inline FramePyramid(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker);
215
216 /**
217 * Creates a frame pyramid based on a frame applying a custom downsampling.
218 * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
219 * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
220 * @param frame The frame for which the pyramid will be created, must be valid
221 * @param layers The number of pyramid layers to be created, with range [1, infinity)
222 * @param worker Optional worker object to distribute the computation
223 */
224 inline FramePyramid(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker);
225
226 /**
227 * Creates a new frame pyramid based on an existing frame pyramid.
228 * @param framePyramid The existing frame pyramid from which the new pyramid will be created, must be valid
229 * @param firstLayerIndex The index of the first layer to use from the source pyramid, with range [0, framePyramid.layers() - 1]
230 * @param layers The number of layers to use from the source pyramid, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to use as many layers as exist
231 * @param copyData True, to make a copy of the image content of the existing pyramid; False, to only use the memory
232 */
233 FramePyramid(const FramePyramid& framePyramid, const unsigned int firstLayerIndex, const unsigned int layers, bool copyData);
234
235 /**
236 * Returns the frame of a specified layer.
237 * @param layer Index of the layer frame to be returned, with range [0, layers())
238 * @return The requested pyramid layer frame
239 */
240 inline const Frame& layer(const unsigned int layer) const;
241
242 /**
243 * Returns the frame of a specified layer.
244 * @param layer Index of the layer frame to be returned, with range [0, layers())
245 * @return The requested pyramid layer frame
246 */
247 inline Frame& layer(const unsigned int layer);
248
249 /**
250 * Returns the finest layer frame of this pyramid.
251 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
252 * @return The finest pyramid layer frame
253 */
254 inline const Frame& finestLayer() const;
255
256 /**
257 * Returns the finest layer frame of this pyramid.
258 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
259 * @return The finest pyramid layer frame
260 */
261 inline Frame& finestLayer();
262
263 /**
264 * Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
265 * If no valid layer is stored in this pyramid, the finest layer is used instead.<br>
266 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!<br>
267 * @return The coarsest pyramid layer frame
268 */
269 inline const Frame& coarsestLayer() const;
270
271 /**
272 * Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
273 * If no valid layer is stored in this pyramid, the finest layer is used instead.<br>
274 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!<br>
275 * @return The coarsest pyramid layer frame
276 */
277 inline Frame& coarsestLayer();
278
279 /**
280 * Returns the number of layers this pyramid holds.
281 * @return Pyramid layers, with range [0, infinity)
282 */
283 inline unsigned int layers() const;
284
285 /**
286 * Returns the width of a given layer.
287 * @param layer The layer to return the width for, with range [0, layers())
288 * @return Width in pixel
289 */
290 inline unsigned int width(const unsigned int layer) const;
291
292 /**
293 * Returns the height of a given layer.
294 * @param layer The layer to return the height for, with range [0, layers())
295 * @return Height in pixel
296 */
297 inline unsigned int height(const unsigned int layer) const;
298
299 /**
300 * Returns the width of the finest (first) layer.
301 * @return Width in pixel
302 */
303 inline unsigned int finestWidth() const;
304
305 /**
306 * Returns the height of the finest (first) layer.
307 * @return Height in pixel
308 */
309 inline unsigned int finestHeight() const;
310
311 /**
312 * Returns the width of the coarsest (last) layer regarding to the number of valid layers.
313 * If no valid layer is stored in this pyramid, the finest layer is used instead.
314 * @return Width in pixel
315 */
316 inline unsigned int coarsestWidth() const;
317
318 /**
319 * Returns the height of the coarsest (last) layer regarding to the number of valid layers.
320 * If no valid layer is stored in this pyramid, the finest layer is used instead.
321 * @return Height in pixel
322 */
323 inline unsigned int coarsestHeight() const;
324
325 /**
326 * Returns the size factor for the coarsest layer in relation to the finest layer regarding to the number of valid layers.
327 * If no valid layer is stored in this pyramid, the finest layer is used instead.
328 * @return Coarsest layer size factor
329 */
330 inline unsigned int coarsestSizeFactor() const;
331
332 /**
333 * Returns the frame type of the finest layer.
334 * Beware: Ensure that the pyramid holds at least one pyramid layer before calling this function.
335 * @return Frame type
336 */
337 inline const FrameType& frameType() const;
338
339 /**
340 * Replaces this frame pyramid based on a new frame.
341 * The function will re-used the existing pyramid's memory if possible.<br>
342 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
343 * @param frame The frame for which the pyramid will be created, must be valid
344 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
345 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
346 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
347 * @param worker Optional worker object to distribute the computation
348 * @return True, if the frame pyramid was replaced
349 * @see replace8BitPerChannel11().
350 */
351 bool replace(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
352
353 /**
354 * Replaces this frame pyramid based on a new frame.
355 * The function will re-used the existing pyramid's memory if possible.<br>
356 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
357 * @param frame The frame for which the pyramid will be created, must be valid
358 * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
359 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
360 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
361 * @param worker Optional worker object to distribute the computation
362 * @return True, if the frame pyramid was replaced
363 * @see replace8BitPerChannel11().
364 */
365 bool replace(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
366
367 /**
368 * Replaces this frame pyramid based on a new frame.
369 * The function will re-used the existing pyramid's memory if possible.<br>
370 * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
371 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
372 * @param frame The frame for which the pyramid will be created, must be valid
373 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
374 * @param worker Optional worker object to distribute the computation
375 * @return True, if the frame pyramid was replaced
376 * @see replace8BitPerChannel11().
377 */
378 bool replace(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker);
379
380 /**
381 * Replaces this frame pyramid based on a new frame.
382 * The function will re-used the existing pyramid's memory if possible.<br>
383 * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
384 * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
385 * @param frame The frame for which the pyramid will be created, must be valid
386 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
387 * @param worker Optional worker object to distribute the computation
388 * @return True, if the frame pyramid was replaced
389 * @see replace8BitPerChannel11().
390 */
391 bool replace(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker);
392
393 /**
394 * Replaces this frame pyramid based on a new frame.
395 * The function will re-used the existing pyramid's memory if possible.<br>
396 * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer).
397 * @param frame The frame for which the pyramid will be created, must be valid
398 * @param width The width of the frame in pixel, with range [1, infinity)
399 * @param height The height of the frame in pixel, with range [1, infinity)
400 * @param channels The number of channels the given frame has, with range [1, infinity)
401 * @param pixelOrigin The pixel origin of the given frame
402 * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
403 * @param layers Number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
404 * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
405 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
406 * @param worker Optional worker object to distribute the computation
407 * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
408 * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
409 * @return True, if the frame pyramid was replaced
410 * @see replace().
411 */
412 bool replace8BitPerChannel(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const DownsamplingMode downsamplingMode, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker, const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED, const Timestamp timestamp = Timestamp(false));
413
414 /**
415 * Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
416 * This function is intentionally restrictive to reduce binary impact when used, use other function or the constructor in case more flexibility is needed an binary size does not matter.<br>
417 * The function will re-use the existing pyramid's memory if possible.
418 * @param frame The frame for which the pyramid will be created, must be valid
419 * @param width The width of the given frame in pixel, with range [1, infinity)
420 * @param height The height of the given frame in pixel, with range [1, infinity)
421 * @param channels The number of channels the given frame has, with range [1, infinity)
422 * @param pixelOrigin The pixel origin of the given frame
423 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
424 * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
425 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
426 * @param worker Optional worker object to distribute the computation
427 * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
428 * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
429 * @return True, if the frame pyramid was replaced
430 * @see isOwner(), replace().
431 */
432 bool replace8BitPerChannel11(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker, const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED, const Timestamp timestamp = Timestamp(false));
433
434 /**
435 * Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
436 * This function is intentionally restrictive to reduce binary impact when used, use other function or the constructor in case more flexibility is needed an binary size does not matter.<br>
437 * The function will re-use the existing pyramid's memory if possible.<br>
438 * This function does not provide the optimal image quality for images with alpha channel, use replace() instead.
439 * @param frame The frame for which the pyramid will be created, with 1 plane and data type DT_UNSIGNED_INTEGER_8, should not contain an alpha channel, must be valid
440 * @param layers The number of pyramid layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
441 * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
442 * @param worker Optional worker object to distribute the computation
443 * @return True, if the frame pyramid was replaced
444 * @see isOwner(), replace().
445 */
446 inline bool replace8BitPerChannel11(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
447
448 /**
449 * Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
450 * The image content of the replaced frame pyramid will be uninitialized.
451 * @param frameType The type of the finest pyramid layer, must be valid
452 * @param forceOwner True, to force the pyramid to be the owner of the memory afterwards; False, to allow that the pyramid is not owning the memory (because the memory is managed outside of this pyramid)
453 * @param layers The number of layers to be created during the resizing, the resulting layers will be as many as possible but not exceed this value, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
454 * @return True, if succeeded
455 */
456 inline bool replace(const FrameType& frameType, const bool forceOwner, const unsigned int layers);
457
458 /**
459 * Reduces the number of pyramid layers.
460 * @param layers The number of pyramid layers, with range [0, layers()]
461 */
462 void reduceLayers(const size_t layers);
463
464 /**
465 * Releases the internal frame layers.
466 */
467 inline void clear();
468
469 /**
470 * Returns whether the frame pyramid is the owner of the entire image data or owner of a specific pyramid layer.
471 * @param layerIndex The index of the layer to be checked, 'AS_MANY_LAYERS_AS_POSSIBLE" to check all layers
472 * @return True, if so
473 */
474 bool isOwner(const unsigned int layerIndex = AS_MANY_LAYERS_AS_POSSIBLE) const;
475
476 /**
477 * Returns whether this pyramid holds at least one frame layer.
478 * @return True, if so
479 */
480 inline bool isValid() const;
481
482 /**
483 * Returns the pyramid's memory block.
484 * This functions is intended for testing purposes only, don't use this function.
485 * @return The pyramid's memory block, if any
486 */
487 inline const Memory& memory() const;
488
489 /**
490 * Move operator
491 * @param right The right frame to assign
492 * @return Reference to this frame
493 */
495
496 /**
497 * Returns the frame of a specified layer.
498 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
499 * @param layer Index of the layer frame to be returned, with range [0, layers())
500 * @return Pyramid layer frame
501 */
502 inline const Frame& operator[](const unsigned int layer) const;
503
504 /**
505 * Returns the frame of a specified layer.
506 * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
507 * @param layer Index of the layer frame to be returned, with range [0, layers())
508 * @return Pyramid layer frame
509 */
510 inline Frame& operator[](const unsigned int layer);
511
512 /**
513 * Returns whether this pyramid holds at least one frame layer.
514 * @return True, if so
515 */
516 explicit inline operator bool() const;
517
518 /**
519 * Returns the size factor of a specified layer in relation to the finest layer.
520 * The finest (first) layer has factor 1, the second layer has factor 2, the third layer has factor 4, ...<br>
521 * @param layerIndex The index of the layer to return the size factor for, with range [0, 31]
522 * @return The resulting size factor, with range [1, infinity)
523 */
524 static constexpr unsigned int sizeFactor(const unsigned int layerIndex);
525
526 /**
527 * Determines the number of layers until an invalid frame size would be reached in the next layer.
528 * @param width The width of the finest layer in pixel, with range [1, infinity)
529 * @param height The height of the finest layer in pixel, with range [1, infinity)
530 * @param invalidCoarsestWidthOrHeight The width or the height of a coarse layer not valid any more, with range [1, infinity)
531 * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
532 * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
533 * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width' or 'height' are smaller or equal than 'invalidCoarsestWidthOrHeight'
534 */
535 static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidthOrHeight, unsigned int* coarsestLayerWidth = nullptr, unsigned int* coarsestLayerHeight = nullptr);
536
537 /**
538 * Determines the number of layers until an invalid frame size would be reached in the next layer.
539 * @param width The width of the finest layer in pixel, with range [1, infinity)
540 * @param height The height of the finest layer in pixel, with range [1, infinity)
541 * @param invalidCoarsestWidth The width of a coarse layer not valid any more, with range [1, infinity)
542 * @param invalidCoarsestHeight The height of a coarse layer not valid any more, with range [1, infinity)
543 * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
544 * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
545 * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width/height' is smaller or equal than 'invalidCoarsestWidth/invalidCoarsestHeight'
546 */
547 static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, unsigned int* coarsestLayerWidth = nullptr, unsigned int* coarsestLayerHeight = nullptr);
548
549 /**
550 * Determines the number of layers until an invalid frame size would be reached in the next layer or an overall size radius is reached.
551 * @param width The width of the finest layer in pixel
552 * @param height The height of the finest layer in pixel
553 * @param invalidCoarsestWidth Width of a coarse layer not valid any more, with range [1, infinity)
554 * @param invalidCoarsestHeight Height of a coarse layer not valid any more, with range [1, infinity)
555 * @param layerFactor Size factor on each layer (a factor of 2 means that the layer dimension is halved on each layer), with range [2, infinity)
556 * @param maximalRadius Maximal radius that can be reached on the finest layer by starting with coarsestLayerRadius on the coarsest layer in pixel (the maximal expected baseline between two pixels in the finest pyramid layer), with range [1, infinity)
557 * @param coarsestLayerRadius The search radius on the coarsest layer, with range [2, infinity)
558 * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
559 * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
560 * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width/height' is smaller or equal than 'invalidCoarsestWidth/invalidCoarsestHeight'
561 */
562 static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, const unsigned int layerFactor, const unsigned int maximalRadius = (unsigned int)(-1), const unsigned int coarsestLayerRadius = 2u, unsigned int* coarsestLayerWidth = nullptr, unsigned int* coarsestLayerHeight = nullptr);
563
564 /**
565 * Determines the ideal coarsest layer radius based on the maximal tracking distance and the number of pyramid layers.
566 * This function is the inverse of idealLayers() with respect to the radius calculation.
567 * The relationship is:
568 * <pre>
569 * maximalRadius = coarsestLayerRadius * (layerFactor ^ (layers - 1))
570 * </pre>
571 * @param maximalRadius Maximal tracking distance in the finest layer in pixel (the maximal expected motion between two pixels in the finest pyramid layer), with range [1, infinity)
572 * @param layers The number of pyramid layers, with range [1, infinity)
573 * @param layerFactor Size factor on each layer (a factor of 2 means that the layer dimension is halved on each layer), with range [2, infinity)
574 * @return The ideal search radius on the coarsest layer in pixel, with range [1, infinity)
575 */
576 static unsigned int idealCoarsestLayerRadius(const unsigned int maximalRadius, const unsigned int layers, const unsigned int layerFactor = 2u);
577
578 /**
579 * Determines the ideal tracking parameters (pyramid layers and coarsest layer search radius) for frame tracking.
580 * This function analyzes various combinations of pyramid layers and search radii to find the optimal configuration that balances performance and tracking precision while respecting the given constraints.
581 *
582 * The function evaluates different parameter combinations and selects the one that:
583 * - Can track the required maximal tracking distance
584 * - Meets all specified constraints (min/max layers and radius)
585 * - Optimizes the performance/precision trade-off
586 *
587 * The search explores "neighboring" parameter options, recognizing that sometimes reducing pyramid layers but increasing the search radius can provide better performance or precision characteristics.
588 * Specifically, fewer layers with larger radius can be more precise by reducing error accumulation through pyramid levels.
589 *
590 * @param width The width of the frame in pixels, with range [1, infinity)
591 * @param height The height of the frame in pixels, with range [1, infinity)
592 * @param invalidCoarsestWidth The width of a coarse layer not valid any more, with range [1, infinity)
593 * @param invalidCoarsestHeight The height of a coarse layer not valid any more, with range [1, infinity)
594 * @param maximalTrackingDistance The maximal tracking distance as a fraction of the frame diagonal, with range (0, infinity)
595 * @param minimalLayers The minimal number of pyramid layers to consider, with range [1, infinity)
596 * @param maximalLayers The maximal number of pyramid layers to consider, with range [minimalLayers, infinity), or 0 to determine automatically based on frame size
597 * @param minimalCoarsestLayerRadius The minimal search radius on the coarsest pyramid layer in pixels, with range [1, infinity)
598 * @param maximalCoarsestLayerRadius The maximal search radius on the coarsest pyramid layer in pixels, with range [minimalCoarsestLayerRadius, infinity)
599 * @param idealLayers The resulting ideal number of pyramid layers
600 * @param idealCoarsestLayerRadius The resulting ideal search radius on the coarsest pyramid layer in pixels
601 * @return True if valid parameters were found; False otherwise
602 */
603 static bool idealTrackingParameters(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, const float maximalTrackingDistance, const unsigned int minimalLayers, const unsigned int maximalLayers, const unsigned int minimalCoarsestLayerRadius, const unsigned int maximalCoarsestLayerRadius, unsigned int& idealLayers, unsigned int& idealCoarsestLayerRadius);
604
605 protected:
606
607 /**
608 * Disabled constructor.
609 */
610 explicit FramePyramid(Frame&&) = delete;
611
612 /**
613 * Disabled constructor.
614 */
615 FramePyramid(const Frame&, const bool) = delete;
616
617 /**
618 * Disabled constructor to prevent confusion between all constructors.
619 */
620 FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, Worker* worker) = delete;
621
622 /**
623 * Disabled constructor to prevent confusion between all constructors.
624 */
625 FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, Worker* worker) = delete;
626
627 /**
628 * Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
629 * The image content of the replaced frame pyramid will be uninitialized.
630 * @param frameType The type of the finest pyramid layer, must be valid
631 * @param reserveFirstLayerMemory True, to reserve memory for the first pyramid layer (and to initialize the first layer frame); False, to reserve memory for the remaining pyramid layers only (and to skip initializing the first layer frame)
632 * @param forceOwner True, to force the pyramid to be the owner of the memory afterwards; False, to allow that the pyramid is not owning the memory (because the memory is managed outside of this pyramid)
633 * @param layers The number of layers to be created during the resizing, the resulting layers will be as many as possible but not exceed this value, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as many layers as possible
634 * @return True, if succeeded
635 */
636 bool replace(const FrameType& frameType, const bool reserveFirstLayerMemory, const bool forceOwner, const unsigned int layers);
637
638 /**
639 * Calculates the size of the entire pyramid in bytes covering all images in all pyramid layers.
640 * @param width The width of the finest layer in pixel, with range [0, 65535]
641 * @param height The height of the finest layer in pixel, with range [0, 65535]
642 * @param pixelFormat The pixel format of each layer, must be a generic 1-plane pixel format, must be valid
643 * @param layers Number of layers, with range [0, infinity), AS_MANY_LAYERS_AS_POSSIBLE to calculate the memory size for as many layers as possible
644 * @param includeFirstLayer True, to determine the memory for all layers; False, to skip the first layer and only determine the memory for all remaining (coarser) layers
645 * @param totalLayers Optional resulting number of pyramid layers that will exist (always counts the very first layer independently of 'includeFirstLayer'), with range [0, layers]
646 * @return Resulting number of bytes, with range [0, infinity)
647 */
648 static size_t calculateMemorySize(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const unsigned int layers, const bool includeFirstLayer, unsigned int* totalLayers = nullptr);
649
650 /**
651 * Deleted function to prevent confusion between Frame and FrameType.
652 * @param frame The potential frame to be used
653 * @param layers The number of layers
654 * @param forceOwner The ownership information
655 * @return True, if succeeded
656 */
657 bool replace(const Frame& frame, const bool forceOwner, const unsigned int layers = AS_MANY_LAYERS_AS_POSSIBLE) = delete;
658
659 /**
660 * Disabled assign operator
661 * Use a constructor or the move operator instead.
662 * @return Reference to this object
663 */
665
666 /**
667 * Downsamples a frame with 1-1 filter.
668 * @param finerLayer The finer pyramid layer, must be valid
669 * @param coarserLayer The coarser pyramid layer, must be valid
670 * @param worker The optional worker to distribute the computation
671 * @return True, if succeeded
672 */
673 static bool downsampleByTwo11(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
674
675 /**
676 * Downsamples a frame with 1-1 filter which contains an alpha channel.
677 * @param finerLayer The finer pyramid layer, must be valid
678 * @param coarserLayer The coarser pyramid layer, must be valid
679 * @param worker The optional worker to distribute the computation
680 * @return True, if succeeded
681 */
682 static bool downsampleAlphaByTwo11(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
683
684 /**
685 * Downsamples a frame with 1-4-6-4-1 filter.
686 * @param finerLayer The finer pyramid layer, must be valid
687 * @param coarserLayer The coarser pyramid layer, must be valid
688 * @param worker The optional worker to distribute the computation
689 * @return True, if succeeded
690 */
691 static bool downsampleByTwo14641(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
692
693 /**
694 * Returns the downsampling function for a specified downsampling mode.
695 * @param downsamplingMode The downsampling mode for which the function will be returned
696 * @param pixelFormat The pixel format for which the downsampling function will be returned, must be valid
697 * @return The downsampling function, nullptr if unknown
698 */
700
701 /**
702 * Deleted function to prevent confusion between several different replace functions.
703 */
704 bool replace(const Frame&, const DownsamplingMode, const unsigned int layers, Worker* worker) = delete;
705
706 /**
707 * Deleted function to prevent confusion between several different replace functions.
708 */
709 bool replace(const Frame&, const DownsamplingFunction&, const unsigned int layers, Worker* worker) = delete;
710
711 protected:
712
713 /// The individual layers of this pyramid, zero if not valid.
715
716 /// Optional memory which may be used by at least one pyramid layer.
718};
719
721{
722 // nothing to do here
723}
724
725inline FramePyramid::FramePyramid(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker, const FrameType::PixelFormat pixelFormat, const Timestamp timestamp)
726{
727 ocean_assert(frame != nullptr && width >= 1u && height >= 1u && layers >= 1u);
728 ocean_assert(channels >= 1u);
729
730 const bool result = replace8BitPerChannel11(frame, width, height, channels, pixelOrigin, layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
731 ocean_assert_and_suppress_unused(result, result);
732}
733
734inline FramePyramid::FramePyramid(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
735{
736 const bool result = replace8BitPerChannel11(frame, layers, copyFirstLayer, worker);
737 ocean_assert_and_suppress_unused(result, result);
738}
739
740inline FramePyramid::FramePyramid(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const DownsamplingMode downsamplingMode, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker* worker, const FrameType::PixelFormat pixelFormat, const Timestamp timestamp)
741{
742 ocean_assert(frame != nullptr && width >= 1u && height >= 1u && layers >= 1u);
743 ocean_assert(channels >= 1u);
744
745 const bool result = replace8BitPerChannel(frame, width, height, channels, pixelOrigin, downsamplingMode, layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
746 ocean_assert_and_suppress_unused(result, result);
747}
748
749inline FramePyramid::FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
750{
751 const bool result = replace(frame, downsamplingMode, layers, copyFirstLayer, worker);
752 ocean_assert_and_suppress_unused(result, result);
753}
754
755inline FramePyramid::FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
756{
757 const bool result = replace(frame, downsamplingFunction, layers, copyFirstLayer, worker);
758 ocean_assert_and_suppress_unused(result, result);
759}
760
761inline FramePyramid::FramePyramid(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker)
762{
763 const bool result = replace(downsamplingMode, std::move(frame), layers, worker);
764 ocean_assert_and_suppress_unused(result, result);
765}
766
767inline FramePyramid::FramePyramid(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker)
768{
769 const bool result = replace(downsamplingFunction, std::move(frame), layers, worker);
770 ocean_assert_and_suppress_unused(result, result);
771}
772
773inline const Frame& FramePyramid::layer(const unsigned int layer) const
774{
775 ocean_assert(layer < layers_.size());
776 return layers_[layer];
777}
778
779inline Frame& FramePyramid::layer(const unsigned int layer)
780{
781 ocean_assert(layer < layers_.size());
782 return layers_[layer];
783}
784
785inline const Frame& FramePyramid::finestLayer() const
786{
787 ocean_assert(isValid());
788 return layers_.front();
789}
790
792{
793 ocean_assert(isValid());
794 return layers_.front();
795}
796
798{
799 ocean_assert(isValid());
800
801 return layers_.back();
802}
803
805{
806 ocean_assert(isValid());
807
808 return layers_.back();
809}
810
811inline unsigned int FramePyramid::layers() const
812{
813 return (unsigned int)layers_.size();
814}
815
816inline unsigned int FramePyramid::width(const unsigned int layer) const
817{
818 ocean_assert(layer < layers_.size());
819 return layers_[layer].width();
820}
821
822inline unsigned int FramePyramid::height(const unsigned int layer) const
823{
824 ocean_assert(layer < layers_.size());
825 return layers_[layer].height();
826}
827
828inline unsigned int FramePyramid::finestWidth() const
829{
830 ocean_assert(isValid());
831 return layers_.front().width();
832}
833
834inline unsigned int FramePyramid::finestHeight() const
835{
836 ocean_assert(isValid());
837 return layers_.front().height();
838}
839
840inline unsigned int FramePyramid::coarsestWidth() const
841{
842 ocean_assert(isValid());
843
844 return layers_.back().width();
845}
846
847inline unsigned int FramePyramid::coarsestHeight() const
848{
849 ocean_assert(isValid());
850
851 return layers_.back().height();
852}
853
855{
856 ocean_assert(isValid());
857
858 return 1u << (unsigned int)((layers_.size() - 1));
859}
860
862{
863 ocean_assert(isValid());
864 return layers_.front().frameType();
865}
866
867inline bool FramePyramid::replace8BitPerChannel11(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
868{
869 ocean_assert(frame.isValid() && frame.numberPlanes() == 1u && frame.dataType() == FrameType::DT_UNSIGNED_INTEGER_8);
870
871 if (frame.numberPlanes() == 1u && frame.dataType() == FrameType::DT_UNSIGNED_INTEGER_8)
872 {
873 return replace8BitPerChannel11(frame.constdata<uint8_t>(), frame.width(), frame.height(), frame.channels(), frame.pixelOrigin(), layers, frame.paddingElements(), copyFirstLayer, worker, frame.pixelFormat(), frame.timestamp());
874 }
875
876 return false;
877}
878
879inline bool FramePyramid::replace(const FrameType& frameType, const bool forceOwner, const unsigned int layers)
880{
881 return replace(frameType, true /*reserveFirstLayerMemory*/, forceOwner, layers);
882}
883
884constexpr unsigned int FramePyramid::sizeFactor(const unsigned int layerIndex)
885{
886 ocean_assert(layerIndex <= 31u);
887 if (layerIndex > 31u)
888 {
889 return 0u;
890 }
891
892 return 1u << layerIndex;
893}
894
896{
897 layers_.clear();
898 memory_.free();
899}
900
901inline const Frame& FramePyramid::operator[](const unsigned int layer) const
902{
903 ocean_assert(layer < layers_.size());
904 return layers_[layer];
905}
906
907inline Frame& FramePyramid::operator[](const unsigned int layer)
908{
909 ocean_assert(layer < layers_.size());
910 return layers_[layer];
911}
912
913inline bool FramePyramid::isValid() const
914{
915 return !layers_.empty();
916}
917
918inline const Memory& FramePyramid::memory() const
919{
920 return memory_;
921}
922
923inline FramePyramid::operator bool() const
924{
925 return isValid();
926}
927
928}
929
930}
931
932#endif // META_OCEAN_CV_FRAME_PYRAMID_H
This class implements a frame pyramid.
Definition FramePyramid.h:46
static CV::FramePyramid::DownsamplingFunction downsamplingFunction(const CV::FramePyramid::DownsamplingMode downsamplingMode, const FrameType::PixelFormat pixelFormat)
Returns the downsampling function for a specified downsampling mode.
const Frame & finestLayer() const
Returns the finest layer frame of this pyramid.
Definition FramePyramid.h:785
FramePyramid(const FramePyramid &framePyramid, const unsigned int firstLayerIndex, const unsigned int layers, bool copyData)
Creates a new frame pyramid based on an existing frame pyramid.
FramePyramid(const unsigned int layers, const FrameType &frameType)
Creates a frame pyramid object for a given frame type and layer number.
bool replace(const Frame &frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker *worker)
Replaces this frame pyramid based on a new frame.
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidthOrHeight, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer.
unsigned int coarsestWidth() const
Returns the width of the coarsest (last) layer regarding to the number of valid layers.
Definition FramePyramid.h:840
FramePyramid(Frame &&)=delete
Disabled constructor.
bool replace8BitPerChannel(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const DownsamplingMode downsamplingMode, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker *worker, const FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED, const Timestamp timestamp=Timestamp(false))
Replaces this frame pyramid based on a new frame.
unsigned int finestWidth() const
Returns the width of the finest (first) layer.
Definition FramePyramid.h:828
bool replace(const Frame &frame, const DownsamplingFunction &downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker *worker)
Replaces this frame pyramid based on a new frame.
void reduceLayers(const size_t layers)
Reduces the number of pyramid layers.
bool replace(const DownsamplingMode downsamplingMode, Frame &&frame, const unsigned int layers, Worker *worker)
Replaces this frame pyramid based on a new frame.
bool replace(const Frame &, const DownsamplingMode, const unsigned int layers, Worker *worker)=delete
Deleted function to prevent confusion between several different replace functions.
const Memory & memory() const
Returns the pyramid's memory block.
Definition FramePyramid.h:918
bool replace(const FrameType &frameType, const bool reserveFirstLayerMemory, const bool forceOwner, const unsigned int layers)
Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
bool isValid() const
Returns whether this pyramid holds at least one frame layer.
Definition FramePyramid.h:913
std::function< bool(const Frame &sourceLayer, Frame &targetLayer, Worker *worker)> DownsamplingFunction
Definition of a function allowing to downsample a frame.
Definition FramePyramid.h:91
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, const unsigned int layerFactor, const unsigned int maximalRadius=(unsigned int)(-1), const unsigned int coarsestLayerRadius=2u, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer or an ...
FramePyramid & operator=(const FramePyramid &)=delete
Disabled assign operator Use a constructor or the move operator instead.
Frames layers_
The individual layers of this pyramid, zero if not valid.
Definition FramePyramid.h:714
unsigned int coarsestHeight() const
Returns the height of the coarsest (last) layer regarding to the number of valid layers.
Definition FramePyramid.h:847
unsigned int width(const unsigned int layer) const
Returns the width of a given layer.
Definition FramePyramid.h:816
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer.
FramePyramid & operator=(FramePyramid &&right) noexcept
Move operator.
DownsamplingMode
Definition of individual down sampling modes.
Definition FramePyramid.h:53
@ DM_FILTER_11
Down sampling is realized by a 2x2 averaging filter.
Definition FramePyramid.h:65
FramePyramid(const Frame &frame, const DownsamplingFunction &downsamplingFunction, const unsigned int layers, Worker *worker)=delete
Disabled constructor to prevent confusion between all constructors.
FramePyramid(const FramePyramid &framePyramid, const bool copyData)
Copy constructor.
const Frame & operator[](const unsigned int layer) const
Returns the frame of a specified layer.
Definition FramePyramid.h:901
void clear()
Releases the internal frame layers.
Definition FramePyramid.h:895
unsigned int coarsestSizeFactor() const
Returns the size factor for the coarsest layer in relation to the finest layer regarding to the numbe...
Definition FramePyramid.h:854
static bool idealTrackingParameters(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, const float maximalTrackingDistance, const unsigned int minimalLayers, const unsigned int maximalLayers, const unsigned int minimalCoarsestLayerRadius, const unsigned int maximalCoarsestLayerRadius, unsigned int &idealLayers, unsigned int &idealCoarsestLayerRadius)
Determines the ideal tracking parameters (pyramid layers and coarsest layer search radius) for frame ...
FramePyramid()
Creates an empty frame pyramid object.
Definition FramePyramid.h:720
const Frame & coarsestLayer() const
Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
Definition FramePyramid.h:797
static unsigned int idealCoarsestLayerRadius(const unsigned int maximalRadius, const unsigned int layers, const unsigned int layerFactor=2u)
Determines the ideal coarsest layer radius based on the maximal tracking distance and the number of p...
static constexpr unsigned int sizeFactor(const unsigned int layerIndex)
Returns the size factor of a specified layer in relation to the finest layer.
Definition FramePyramid.h:884
static size_t calculateMemorySize(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const unsigned int layers, const bool includeFirstLayer, unsigned int *totalLayers=nullptr)
Calculates the size of the entire pyramid in bytes covering all images in all pyramid layers.
unsigned int layers() const
Returns the number of layers this pyramid holds.
Definition FramePyramid.h:811
static bool downsampleByTwo11(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-1 filter.
FramePyramid(const Frame &, const bool)=delete
Disabled constructor.
bool replace(const Frame &frame, const bool forceOwner, const unsigned int layers=AS_MANY_LAYERS_AS_POSSIBLE)=delete
Deleted function to prevent confusion between Frame and FrameType.
static bool downsampleAlphaByTwo11(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-1 filter which contains an alpha channel.
bool replace(const Frame &, const DownsamplingFunction &, const unsigned int layers, Worker *worker)=delete
Deleted function to prevent confusion between several different replace functions.
Memory memory_
Optional memory which may be used by at least one pyramid layer.
Definition FramePyramid.h:717
FramePyramid(const Frame &frame, const DownsamplingMode downsamplingMode, const unsigned int layers, Worker *worker)=delete
Disabled constructor to prevent confusion between all constructors.
bool replace8BitPerChannel11(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker *worker, const FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED, const Timestamp timestamp=Timestamp(false))
Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying ...
const FrameType & frameType() const
Returns the frame type of the finest layer.
Definition FramePyramid.h:861
unsigned int finestHeight() const
Returns the height of the finest (first) layer.
Definition FramePyramid.h:834
unsigned int height(const unsigned int layer) const
Returns the height of a given layer.
Definition FramePyramid.h:822
bool isOwner(const unsigned int layerIndex=AS_MANY_LAYERS_AS_POSSIBLE) const
Returns whether the frame pyramid is the owner of the entire image data or owner of a specific pyrami...
FramePyramid(FramePyramid &&framePyramid) noexcept
Move constructor.
static bool downsampleByTwo14641(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-4-6-4-1 filter.
const Frame & layer(const unsigned int layer) const
Returns the frame of a specified layer.
Definition FramePyramid.h:773
bool replace(const DownsamplingFunction &downsamplingFunction, Frame &&frame, const unsigned int layers, Worker *worker)
Replaces this frame pyramid based on a new frame.
This class implements Ocean's image class.
Definition Frame.h:1879
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition Frame.h:4332
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4612
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition Frame.h:4302
unsigned int size(const unsigned int planeIndex=0u) const
Returns the number of bytes necessary for a specific plane including optional padding at the end of p...
Definition Frame.h:4198
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition Frame.h:4206
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3241
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition Frame.h:3286
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3281
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3251
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3246
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3271
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition Frame.h:3261
This class implements an object able to allocate memory.
Definition base/Memory.h:22
void free()
Explicitly frees (releases) the memory before this object is released.
Definition base/Memory.h:370
This class implements a timestamp.
Definition Timestamp.h:63
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition Frame.h:1842
std::vector< FramePyramid > FramePyramids
Definition of a vector holding frame pyramid objects.
Definition FramePyramid.h:36
The namespace covering the entire Ocean framework.
Definition Accessor.h:15