Ocean
FrameMean.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_MEAN_H
9 #define META_OCEAN_CV_FRAME_MEAN_H
10 
11 #include "ocean/cv/CV.h"
15 
16 #include "ocean/base/Frame.h"
17 #include "ocean/base/Worker.h"
18 
19 namespace Ocean
20 {
21 
22 namespace CV
23 {
24 
25 /**
26  * This class implements functions allowing to determine e.g., the mean pixel value of a frame of a mean frame based on several frames.
27  * @ingroup cv
28  */
29 class OCEAN_CV_EXPORT FrameMean
30 {
31  public:
32 
33  /**
34  * Determines the mean pixel value for a given frame.
35  * @param frame The data of the frame for which the mean value will be determined, must be valid
36  * @param width The width of the given frame in pixel, with range [1, infinity)
37  * @param height The height of the given frame in pixel, with range [1, infinity)
38  * @param meanValues The resulting mean values, one for each channel
39  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
40  * @param worker An optional worker object to distribute the computation
41  * @tparam T The data type of each pixel channel
42  * @tparam TMean The data type of each mean value
43  * @tparam tChannels The number of frame channels, with range [1, infinity)
44  */
45  template <typename T, typename TMean, unsigned int tChannels>
46  static void meanValue(const T* frame, const unsigned int width, const unsigned int height, TMean* meanValues, const unsigned int framePaddingElements, Worker* worker = nullptr);
47 
48  /**
49  * Determines the mean frame for a given set of frames.
50  * The resulting mean frame is determined by adding the pixel color values of all frames individually with a subsequent normalization (by the number of frames).<br>
51  * Beware: This function cannot handle more than 16843010 frames.<br>
52  * @param frameProviderInterface The frame provider interface providing the set of frames, must be initialized
53  * @param targetPixelFormat The pixel format of the resulting mean frame, every frame from the frame provider will be converted into this pixel format before any application
54  * @param firstFrameIndex The index of the first frame from the frame provider interface which is used to determine the mean frame
55  * @param lastFrameIndex The index of the last (including) frame from the frame provider interface, with range [first, number frames from the interface)
56  * @param worker An optional worker object to distribute the computation
57  * @param abort An optional abort statement allowing to abort the determination at any time; set the value True to abort the request
58  * @return The resulting mean frame
59  * @see meanFrame8BitPerChannel().
60  */
61  static Frame meanFrame(FrameProviderInterface& frameProviderInterface, const FrameType::PixelFormat& targetPixelFormat, const unsigned int firstFrameIndex, const unsigned int lastFrameIndex, Worker* worker = nullptr, bool* abort = nullptr);
62 
63  /**
64  * Determines the mean frame for a given set of frames.
65  * The resulting mean frame is determined by adding the pixel color values of all frames individually with a subsequent normalization (by the number of frames).<br>
66  * @param frameProviderInterface The frame provider interface providing the set of frames, must be initialized
67  * @param targetPixelFormat The pixel format of the resulting mean frame, every frame from the frame provider will be converted into this pixel format before any application
68  * @param firstFrameIndex The index of the first frame from the frame provider interface which is used to determine the mean frame
69  * @param lastFrameIndex The index of the last (including) frame from the frame provider interface, with range [first, number frames from the interface)
70  * @param worker An optional worker object to distribute the computation
71  * @param abort An optional abort statement allowing to abort the determination at any time; set the value True to abort the request
72  * @return The resulting mean frame
73  * @tparam tChannels The number of frame data channels which must correspond to the given targetPixelFormat
74  * @see meanFrame().
75  */
76  template <unsigned int tChannels>
77  static Frame meanFrame8BitPerChannel(FrameProviderInterface& frameProviderInterface, const FrameType::PixelFormat& targetPixelFormat, const unsigned int firstFrameIndex, const unsigned int lastFrameIndex, Worker* worker = nullptr, bool* abort = nullptr);
78 
79  /**
80  * Adds the individual pixel values of a given source frame to a target frame.
81  * @param source The source frame which pixels values are copied
82  * @param target The target frame to which the source pixel values will be added, individually for each pixel and channel
83  * @param width The width of both frames in pixels, with range [1, infinity)
84  * @param height The height of both frames in pixels, with range [1, infinity)
85  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
86  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
87  * @param worker An optional worker object to distribute the computation
88  * @tparam TSource The data type of the elements of the source frame
89  * @tparam TTarget The data type of the elements of the target frame
90  * @tparam tChannels The number of frame data channels, with range [1, infinity)
91  */
92  template <typename TSource, typename TTarget, unsigned int tChannels>
93  static inline void addToFrame(const TSource* const source, TTarget* const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
94 
95  /**
96  * Adds the individual pixel values of a given source frame to a target frame if the corresponding mask pixel is valid.
97  * @param source The source frame which pixels values are copied, must be valid and not have more than 4 channels and an 8 bit, unsigned data type
98  * @param mask The mask frame defining whether a source pixel is copied or not (and whether the corresponding normalization denominator of the target frame is increased by 1), must be valid and the data type must 8 bit, unsigned
99  * @param target The target frame to which the source pixel values will be added, must be valid and the frame type like source except that the data type must be 32 bit, unsigned
100  * @param denominators The denominator values individually for each pixel, must be valid and the data type must be 32 bit, unsigned
101  * @param worker An optional worker object to distribute the computation
102  * @param nonMaskValue The value indicating invalid mask pixels, i.e. pixels that should not be processed by this function, all other values will be interpreted as valid, range: [0, 255]
103  * @return True, if succeeded
104  */
105  static bool addToFrameIndividually(const Frame& source, const Frame& mask, Frame& target, Frame& denominators, const uint8_t nonMaskValue, Worker* worker = nullptr);
106 
107  /**
108  * Adds the individual pixel values of a given source frame to a target frame if the corresponding mask pixel is valid.
109  * @param source The source frame which pixels values are copied
110  * @param mask The mask frame defining whether a source pixel is copied or not (and whether the corresponding normalization denominator of the target frame is increased by 1)
111  * @param target The target frame to which the source pixel values will be added
112  * @param denominators The denominator values individually for each pixel
113  * @param width The width of both frames in pixels, with range [1, infinity)
114  * @param height The height of both frames in pixels, with range [1, infinity)
115  * @param sourcePaddingElements The number of padding elements of the source frame, range: [0, infinity)
116  * @param maskPaddingElements The number of padding elements of the mask frame, range: [0, infinity)
117  * @param targetPaddingElements The number of padding elements of the target frame, range: [0, infinity)
118  * @param denominatorsPaddingElements The number of padding elements of the denominators frame, range: [0, infinity)
119  * @param nonMaskValue The value indicating invalid mask pixels, i.e. pixels that should not be processed by this function, all other values will be interpreted as valid, range: [0, 255]
120  * @param worker An optional worker object to distribute the computation
121  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
122  */
123  template <unsigned int tChannels>
124  static inline void addToFrameIndividually8BitPerChannel(const uint8_t* source, const uint8_t* mask, unsigned int* target, unsigned int* denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, Worker* worker = nullptr);
125 
126  /**
127  * Adds the individual pixel values of a given source frame to a target frame.
128  * @param source The source frame which pixels values are copied
129  * @param targetWithDenominator The target frame to which the source pixel values will be added, with individual denominator values, the denominator of each pixel is increased by 1
130  * @param width The width of both frames in pixels, with range [1, infinity)
131  * @param height The height of both frames in pixels, with range [1, infinity)
132  * @param worker An optional worker object to distribute the computation
133  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
134  */
135  template <unsigned int tChannels>
136  static inline void addToFrameIndividually8BitPerChannel(const uint8_t* source, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, Worker* worker = nullptr);
137 
138  /**
139  * Adds the individual pixel values of a given source frame to a target frame if the corresponding mask pixel is valid.
140  * @param source The source frame which pixels values are copied
141  * @param mask The mask frame defining whether a source pixel is copied or not (and whether the corresponding normalization denominator of the target frame is increased by 1)
142  * @param targetWithDenominator The target frame to which the source pixel values will be added, with individual denominator values
143  * @param width The width of both frames in pixels, with range [1, infinity)
144  * @param height The height of both frames in pixels, with range [1, infinity)
145  * @param worker An optional worker object to distribute the computation
146  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
147  */
148  template <unsigned int tChannels>
149  static inline void addToFrameIndividually8BitPerChannel(const uint8_t* source, const uint8_t* mask, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, Worker* worker = nullptr);
150 
151  /**
152  * Normalizes the pixels values of a given (accumulated frame) by a given denominator.
153  * @param source The accumulated source frame which has to be normalized, must be valid
154  * @param target The target frame which receives the normalized source frame, must be valid
155  * @param denominator The denominator which is used to normalize each frame pixel and channel of the source frame, with range [1, infinity)
156  * @param width The width of both frames in pixels, with range [1, infinity)
157  * @param height The height of both frames in pixels, with range [1, infinity)
158  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
159  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
160  * @param worker An optional worker object to distribute the computation
161  * @tparam TSource The data type of the elements of the source frame
162  * @tparam TTarget The data type of the elements of the target frame
163  * @tparam tChannels The number of frame data channels, with range [1, infinity)
164  */
165  template <typename TSource, typename TTarget, unsigned int tChannels>
166  static inline void normalizeFrame(const TSource* const source, TTarget* const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
167 
168  /**
169  * Normalizes the pixels values of a given (accumulated frame) by individual denominator values.
170  * The denominator values are provided as a second frame with corresponding pixel layout as the source frame.<br>
171  * @param source The accumulated source frame which has to be normalized
172  * @param denominators The normalization denominator frame individually for each pixel, with range [0, infinity)
173  * @param target The target frame which receives the normalized source frame
174  * @param width The width of both frames in pixels, with range [1, infinity)
175  * @param height The height of both frames in pixels, with range [1, infinity)
176  * @param zeroValue The target pixel value for pixels with denominator value equal to zero
177  * @param worker An optional worker object to distribute the computation
178  * @tparam tChannels The number of frame data channels
179  */
180  template <unsigned int tChannels>
181  static inline void normalizeFrameIndividually8BitPerChannel(const unsigned int* source, const unsigned int* denominators, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue = nullptr, Worker* worker = nullptr);
182 
183  /**
184  * Normalizes the pixels values of a given (accumulated frame) by individual denominator values.
185  * @param sourceWithDenominator The accumulated source frame together with the individual denominator values
186  * @param target The target frame which receives the normalized source frame
187  * @param width The width of both frames in pixels, with range [1, infinity)
188  * @param height The height of both frames in pixels, with range [1, infinity)
189  * @param zeroValue The target pixel value for pixels with denominator value equal to zero
190  * @param worker An optional worker object to distribute the computation
191  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
192  */
193  template <unsigned int tChannels>
194  static inline void normalizeFrameIndividually8BitPerChannel(const unsigned int* sourceWithDenominator, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, Worker* worker = nullptr);
195 
196  protected:
197 
198  /**
199  * Sums the pixel values in a subset of a given frame.
200  * @param frame The data of the frame for which the summed pixel values will be determined, must be valid
201  * @param width The width of the given frame in pixel, with range [1, infinity)
202  * @param sumValues The resulting summed pixel values values, one for each channel
203  * @param lock Lock object which must be provided if this function is invoked in parallel; nullptr otherwise
204  * @param framePaddingElements The number of padding elements at the end of each image row, in elements, with range [0, infinity)
205  * @param firstRow The first row to be handled, with range [0, 'frame height')
206  * @param numberRows The number of rows to be handled, with range [1, 'frame height' - firstRow]
207  * @tparam T The data type of each pixel channel
208  * @tparam TSum Data type of each sum value
209  * @tparam tChannels The number of frame channels, with range [1, infinity)
210  */
211  template <typename T, typename TSum, unsigned int tChannels>
212  static void sumFrameSubset(const T* frame, const unsigned int width, TSum* sumValues, Lock* lock, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows);
213 
214  /**
215  * Adds the subset of individual pixel values of a given source frame to a target frame.
216  * @param source The source frame which pixels values are copied, must be valid
217  * @param target The target frame to which the source pixel values will be added, individually for each pixel and channel, must be valid
218  * @param width The width of both frames in pixels, with range [1, infinity)
219  * @param height The height of both frames in pixels, with range [1, infinity)
220  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
221  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
222  * @param firstRow The first row to be handled, with range [0, height - 1]
223  * @param numberRows The number of rows to be handled, with range [1, height - firstRow]
224  * @tparam TSource The data type of the elements of the source frame
225  * @tparam TTarget The data type of the elements of the target frame
226  * @tparam tChannels The number of frame data channels, with range [1, infinity)
227  */
228  template <typename TSource, typename TTarget, unsigned int tChannels>
229  static void addToFrameSubset(const TSource* const source, TTarget* const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows);
230 
231  /**
232  * Adds the subset of individual pixel values of a given source frame to a target frame (with denominators as separate block) if the corresponding mask pixel is valid.
233  * @param source The source frame from which pixels values are copied
234  * @param mask The mask frame defining whether a source pixel is copied or not (and whether the corresponding normalization denominator of the target frame is increased by 1)
235  * @param target The target frame to which the source pixel values will be added
236  * @param denominators The denominator values individually for each pixel
237  * @param width The width of both frames in pixels
238  * @param height The height of both frames in pixels
239  * @param sourcePaddingElements The number of padding elements of the source frame, range: [0, infinity)
240  * @param maskPaddingElements The number of padding elements of the mask frame, range: [0, infinity)
241  * @param targetPaddingElements The number of padding elements of the target frame, range: [0, infinity)
242  * @param denominatorsPaddingElements The number of padding elements of the denominators frame, range: [0, infinity)
243  * @param nonMaskValue The value indicating invalid mask pixels, i.e. pixels that should not be processed by this function, all other values will be interpreted as valid, range: [0, 255]
244  * @param firstRow The first row to be handled
245  * @param numberRows The number of rows to be handled
246  * @tparam tChannels The number of frame data channels
247  */
248  template <unsigned int tChannels>
249  static void addToFrameIndividuallyBlock8BitPerChannelSubset(const uint8_t* source, const uint8_t* mask, unsigned int* target, unsigned int* denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, const unsigned int firstRow, const unsigned int numberRows);
250 
251  /**
252  * Adds the subset of individual pixel values of a given source frame to a target frame (with zipped denominator).
253  * @param source The source frame from which pixels values are copied
254  * @param targetWithDenominator The target frame to which the source pixel values will be added, with individual denominator values, the denominator of each pixel is increased by 1
255  * @param width The width of both frames in pixels
256  * @param height The height of both frames in pixels
257  * @param firstRow The first row to be handled
258  * @param numberRows The number of rows to be handled
259  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
260  */
261  template <unsigned int tChannels>
262  static void addToFrameIndividuallyZipped8BitPerChannelSubset(const uint8_t* source, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, const unsigned int firstRow, const unsigned int numberRows);
263 
264  /**
265  * Adds the subset of individual pixel values of a given source frame to a target frame (with zipped denominator) if the corresponding mask pixel is valid.
266  * @param source The source frame from which pixels values are copied
267  * @param mask The mask frame defining whether a source pixel is copied or not (and whether the corresponding normalization denominator of the target frame is increased by 1)
268  * @param targetWithDenominator The target frame to which the source pixel values will be added, with individual denominator values
269  * @param width The width of both frames in pixels
270  * @param height The height of both frames in pixels
271  * @param firstRow The first row to be handled
272  * @param numberRows The number of rows to be handled
273  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
274  */
275  template <unsigned int tChannels>
276  static void addToFrameIndividuallyZipped8BitPerChannelSubset(const uint8_t* source, const uint8_t* mask, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, const unsigned int firstRow, const unsigned int numberRows);
277 
278  /**
279  * Normalizes a subset of the pixels values of a given (accumulated frame) by a given denominator.
280  * @param source The accumulated source frame which has to be normalized, must be valid
281  * @param target The target frame which receives the normalized source frame, must be valid
282  * @param denominator The denominator which is used to normalize each frame pixel and channel of the source frame, with range [1, infinity)
283  * @param width The width of both frames in pixels, with range [1, infinity)
284  * @param height The height of both frames in pixels, with range [1, infinity)
285  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
286  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
287  * @param firstRow The first row to be handled, with range [0, height - 1]
288  * @param numberRows The number of rows to be handled, with range [1, height - firstRow]
289  * @tparam TSource The data type of the elements of the source frame
290  * @tparam TTarget The data type of the elements of the target frame
291  * @tparam tChannels The number of frame data channels, with range [1, infinity)
292  */
293  template <typename TSource, typename TTarget, unsigned int tChannels>
294  static void normalizeFrameSubset(const TSource* const source, TTarget* const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows);
295 
296  /**
297  * Normalizes a subset of the pixels values of a given (accumulated frame) by individual denominator values.
298  * @param source The accumulated source frame which has to be normalized
299  * @param denominators The normalization denominators individually for each pixel, with range [0, infinity)
300  * @param target The target frame which receives the normalized source frame
301  * @param width The width of both frames in pixels
302  * @param height The height of both frames in pixels
303  * @param zeroValue The target pixel value for pixels with denominator value equal to zero
304  * @param firstRow The first row to be handled
305  * @param numberRows The number of rows to be handled
306  * @tparam tChannels The number of frame data channels
307  */
308  template <unsigned int tChannels>
309  static void normalizeFrameIndividually8BitPerChannelSubset(const unsigned int* source, const unsigned int* denominators, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, const unsigned int firstRow, const unsigned int numberRows);
310 
311  /**
312  * Normalizes a subset of the pixels values of a given (accumulated frame) by individual denominator values.
313  * @param sourceWithDenominator The accumulated source frame together with the individual denominator values
314  * @param target The target frame which receives the normalized source frame
315  * @param width The width of both frames in pixels
316  * @param height The height of both frames in pixels
317  * @param zeroValue The target pixel value for pixels with denominator value equal to zero
318  * @param firstRow The first row to be handled
319  * @param numberRows The number of rows to be handled
320  * @tparam tChannels The number of frame data channels, not including the extra channel for the denominator value
321  */
322  template <unsigned int tChannels>
323  static void normalizeFrameIndividually8BitPerChannelSubset(const unsigned int* sourceWithDenominator, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, const unsigned int firstRow, const unsigned int numberRows);
324 };
325 
326 template <typename T, typename TMean, unsigned int tChannels>
327 void FrameMean::meanValue(const T* frame, const unsigned int width, const unsigned int height, TMean* meanValues, const unsigned int framePaddingElements, Worker* worker)
328 {
329  static_assert(tChannels > 0u, "Invalid channel number!");
330 
331  ocean_assert(frame != nullptr && meanValues != nullptr);
332  ocean_assert(width > 0u && height > 0u);
333 
334  typedef typename NextLargerTyper<T>::TypePerformance TSum;
335 
336  TSum sumValues[tChannels];
337  for (unsigned int n = 0u; n < tChannels; ++n)
338  {
339  sumValues[n] = TSum(0);
340  }
341 
342  if (worker)
343  {
344  Lock lock;
345  worker->executeFunction(Worker::Function::createStatic(sumFrameSubset<T, TSum, tChannels>, frame, width, sumValues, &lock, framePaddingElements, 0u, 0u), 0u, height, 5u, 6u, 40u);
346  }
347  else
348  {
349  sumFrameSubset<T, TSum, tChannels>(frame, width, sumValues, nullptr, framePaddingElements, 0u, height);
350  }
351 
352  const unsigned int pixels = width * height;
353 
354  for (unsigned int n = 0u; n < tChannels; ++n)
355  {
356  // we apply a simple division for floating point values
357  // and add a rounding for non floating point values
358 
359  if constexpr (std::is_same<float, TMean>::value || std::is_same<double, TMean>::value)
360  {
361  meanValues[n] = TMean(double(sumValues[n]) / double(pixels));
362  }
363  else
364  {
365  meanValues[n] = TMean((sumValues[n] + TSum(pixels) / TSum(2)) / TSum(pixels));
366  }
367  }
368 }
369 
370 template <unsigned int tChannels>
371 Frame FrameMean::meanFrame8BitPerChannel(FrameProviderInterface& frameProviderInterface, const FrameType::PixelFormat& targetPixelFormat, const unsigned int firstFrameIndex, const unsigned int lastFrameIndex, Worker* worker, bool* abort)
372 {
373  static_assert(tChannels >= 1u, "Invalid channel number!");
374 
375  ocean_assert(frameProviderInterface.isInitialized());
376  ocean_assert(firstFrameIndex <= lastFrameIndex);
377 
378  ocean_assert(FrameType::channels(targetPixelFormat) == tChannels);
379 
380  const FrameType sourceFrameType = frameProviderInterface.synchronFrameTypeRequest(10, abort);
381  ocean_assert(sourceFrameType.isValid());
382 
383  const unsigned int interfaceNumberFrames = frameProviderInterface.synchronFrameNumberRequest(10, abort);
384  ocean_assert(lastFrameIndex < interfaceNumberFrames);
385 
386  const unsigned int meanFrames = lastFrameIndex - firstFrameIndex + 1u;
387  ocean_assert(meanFrames >= 1u && meanFrames < 16843010u);
388 
389  const unsigned int width = sourceFrameType.width();
390  const unsigned int height = sourceFrameType.height();
391 
392  const FrameType targetFrameType(sourceFrameType, targetPixelFormat);
393 
394  ocean_assert(width > 0u && height > 0u);
395  if (width == 0u || height == 0u || meanFrames >= 16843010u || interfaceNumberFrames <= lastFrameIndex)
396  {
397  return Frame();
398  }
399 
400  Frame accumulatedFrame(FrameType(width, height, FrameType::genericPixelFormat<uint32_t, tChannels>(), FrameType::ORIGIN_UPPER_LEFT));
401  accumulatedFrame.setValue(0x00u);
402 
403  for (unsigned int n = firstFrameIndex; n <= lastFrameIndex; ++n)
404  {
405  const FrameRef frame(frameProviderInterface.synchronFrameRequest(n, 10, abort));
406 
407  if (n + 1u <= lastFrameIndex)
408  {
409  frameProviderInterface.frameCacheRequest(n + 1u, n + 1u);
410  }
411 
412  if (frame.isNull() || !frame->isValid())
413  {
414  return Frame();
415  }
416 
417  Frame targetFrame;
418 
419  if (!CV::FrameConverter::Comfort::convert(*frame, targetFrameType.pixelFormat(), targetFrameType.pixelOrigin(), targetFrame, CV::FrameConverter::CP_AVOID_COPY_IF_POSSIBLE, worker))
420  {
421  return Frame();
422  }
423 
424  addToFrame<uint8_t, uint32_t, tChannels>(targetFrame.constdata<uint8_t>(), accumulatedFrame.data<uint32_t>(), width, height, targetFrame.paddingElements(), accumulatedFrame.paddingElements(), worker);
425  }
426 
427  Frame result(targetFrameType);
428 
429  normalizeFrame<uint32_t, uint8_t, tChannels>(accumulatedFrame.constdata<uint32_t>(), result.data<uint8_t>(), meanFrames, width, height, accumulatedFrame.paddingElements(), result.paddingElements(), worker);
430 
431  return result;
432 }
433 
434 template <typename TSource, typename TTarget, unsigned int tChannels>
435 inline void FrameMean::addToFrame(const TSource* const source, TTarget* const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
436 {
437  static_assert(sizeof(TSource) <= sizeof(TTarget), "Invalid data type!");
438  static_assert(tChannels >= 1u, "Invalid channel number!");
439 
440  ocean_assert(source != nullptr && target != nullptr);
441  ocean_assert(width != 0u && height != 0u);
442 
443  if (worker)
444  {
445  worker->executeFunction(Worker::Function::createStatic(&FrameMean::addToFrameSubset<TSource, TTarget, tChannels>, source, target, width, height, sourcePaddingElements, targetPaddingElements, 0u, 0u), 0u, height);
446  }
447  else
448  {
449  addToFrameSubset<TSource, TTarget, tChannels>(source, target, width, height, sourcePaddingElements, targetPaddingElements, 0u, height);
450  }
451 }
452 
453 template <unsigned int tChannels>
454 inline void FrameMean::addToFrameIndividually8BitPerChannel(const uint8_t* source, const uint8_t* mask, unsigned int* target, unsigned int* denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, Worker* worker)
455 {
456  static_assert(tChannels >= 1u, "Invalid channel number!");
457 
458  ocean_assert(source && mask && target && denominators);
459  ocean_assert(width != 0u && height != 0u);
460 
461  if (worker)
462  {
463  worker->executeFunction(Worker::Function::createStatic(&FrameMean::addToFrameIndividuallyBlock8BitPerChannelSubset<tChannels>, source, mask, target, denominators, width, height, sourcePaddingElements, maskPaddingElements, targetPaddingElements, denominatorsPaddingElements, nonMaskValue, 0u, 0u), 0u, height);
464  }
465  else
466  {
467  addToFrameIndividuallyBlock8BitPerChannelSubset<tChannels>(source, mask, target, denominators, width, height, sourcePaddingElements, maskPaddingElements, targetPaddingElements, denominatorsPaddingElements, nonMaskValue, 0u, height);
468  }
469 }
470 
471 template <unsigned int tChannels>
472 inline void FrameMean::addToFrameIndividually8BitPerChannel(const uint8_t* source, const uint8_t* mask, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, Worker* worker)
473 {
474  static_assert(tChannels >= 1u, "Invalid channel number!");
475 
476  ocean_assert(source && mask && targetWithDenominator);
477  ocean_assert(width != 0u && height != 0u);
478 
479  if (worker)
480  {
481  worker->executeFunction(Worker::Function::createStatic(&FrameMean::addToFrameIndividuallyZipped8BitPerChannelSubset<tChannels>, source, mask, targetWithDenominator, width, height, 0u, 0u), 0u, height, 5u, 6u);
482  }
483  else
484  {
485  addToFrameIndividuallyZipped8BitPerChannelSubset<tChannels>(source, mask, targetWithDenominator, width, height, 0u, height);
486  }
487 }
488 
489 template <unsigned int tChannels>
490 inline void FrameMean::addToFrameIndividually8BitPerChannel(const uint8_t* source, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, Worker* worker)
491 {
492  static_assert(tChannels >= 1u, "Invalid channel number!");
493 
494  ocean_assert(source && targetWithDenominator);
495  ocean_assert(width != 0u && height != 0u);
496 
497  if (worker)
498  {
499  worker->executeFunction(Worker::Function::createStatic(&FrameMean::addToFrameIndividuallyZipped8BitPerChannelSubset<tChannels>, source, targetWithDenominator, width, height, 0u, 0u), 0u, height, 4u, 5u);
500  }
501  else
502  {
503  addToFrameIndividuallyZipped8BitPerChannelSubset<tChannels>(source, targetWithDenominator, width, height, 0u, height);
504  }
505 }
506 
507 template <typename TSource, typename TTarget, unsigned int tChannels>
508 inline void FrameMean::normalizeFrame(const TSource* const source, TTarget* const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
509 {
510  static_assert(tChannels >= 1u, "Invalid channel number!");
511 
512  ocean_assert(source != nullptr && target != nullptr);
513  ocean_assert(width != 0u && height != 0u);
514 
515  if (worker)
516  {
517  worker->executeFunction(Worker::Function::createStatic(&FrameMean::normalizeFrameSubset<TSource, TTarget, tChannels>, source, target, denominator, width, height, sourcePaddingElements, targetPaddingElements, 0u, 0u), 0u, height);
518  }
519  else
520  {
521  normalizeFrameSubset<TSource, TTarget, tChannels>(source, target, denominator, width, height, sourcePaddingElements, targetPaddingElements, 0u, height);
522  }
523 }
524 
525 template <unsigned int tChannels>
526 inline void FrameMean::normalizeFrameIndividually8BitPerChannel(const unsigned int* source, const unsigned int* denominators, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, Worker* worker)
527 {
528  static_assert(tChannels >= 1u, "Invalid channel number!");
529 
530  ocean_assert(source && denominators && target);
531  ocean_assert(width != 0u && height != 0u);
532 
533  const uint8_t zeroPixel[tChannels] = {0u};
534 
535  if (worker)
536  {
537  worker->executeFunction(Worker::Function::createStatic(&FrameMean::normalizeFrameIndividually8BitPerChannelSubset<tChannels>, source, denominators, target, width, height, zeroValue ? zeroValue : zeroPixel, 0u, 0u), 0u, height, 6u, 7u);
538  }
539  else
540  {
541  normalizeFrameIndividually8BitPerChannelSubset<tChannels>(source, denominators, target, width, height, zeroValue ? zeroValue : zeroPixel, 0u, height);
542  }
543 }
544 
545 template <unsigned int tChannels>
546 inline void FrameMean::normalizeFrameIndividually8BitPerChannel(const unsigned int* sourceWithDenominator, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, Worker* worker)
547 {
548  static_assert(tChannels >= 1u, "Invalid channel number!");
549 
550  ocean_assert(sourceWithDenominator && target);
551  ocean_assert(width != 0u && height != 0u);
552 
553  const uint8_t zeroPixel[tChannels] = {0u};
554 
555  if (worker)
556  {
557  worker->executeFunction(Worker::Function::createStatic(&FrameMean::normalizeFrameIndividually8BitPerChannelSubset<tChannels>, sourceWithDenominator, target, width, height, zeroValue ? zeroValue : zeroPixel, 0u, 0u), 0u, height, 5u, 6u);
558  }
559  else
560  {
561  normalizeFrameIndividually8BitPerChannelSubset<tChannels>(sourceWithDenominator, target, width, height, zeroValue ? zeroValue : zeroPixel, 0u, height);
562  }
563 }
564 
565 template <typename T, typename TSum, unsigned int tChannels>
566 void FrameMean::sumFrameSubset(const T* frame, const unsigned int width, TSum* sumValues, Lock* lock, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
567 {
568  static_assert(tChannels >= 1u, "Invalid channel number!");
569 
570  ocean_assert(frame != nullptr && sumValues != nullptr);
571  ocean_assert(width > 0u);
572 
573  TSum localSumValues[tChannels];
574 
575  for (unsigned int n = 0u; n < tChannels; ++n)
576  {
577  localSumValues[n] = TSum(0);
578  }
579 
580  const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
581 
582  frame += firstRow * frameStrideElements;
583 
584  for (unsigned int y = firstRow; y < firstRow + numberRows; ++y)
585  {
586  const T* frameRowEnd = frame + width * tChannels;
587 
588  while (frame != frameRowEnd)
589  {
590  ocean_assert(frame < frameRowEnd);
591 
592  for (unsigned int n = 0u; n < tChannels; ++n)
593  {
594 #ifdef OCEAN_DEBUG
595  // checking for an overflow
596 
597  if (TSum(frame[n]) > TSum(0))
598  {
599  ocean_assert(NumericT<TSum>::maxValue() - TSum(frame[n]) > localSumValues[n]);
600  }
601  else
602  {
603  ocean_assert(NumericT<TSum>::minValue() - TSum(frame[n]) <= localSumValues[n]);
604  }
605 #endif
606 
607  localSumValues[n] += TSum(frame[n]);
608  }
609 
610  frame += tChannels;
611  }
612 
613  frame += framePaddingElements;
614  }
615 
616  const OptionalScopedLock scopedLock(lock);
617 
618  for (unsigned int n = 0u; n < tChannels; ++n)
619  {
620  sumValues[n] += localSumValues[n];
621  }
622 }
623 
624 template <typename TSource, typename TTarget, unsigned int tChannels>
625 void FrameMean::addToFrameSubset(const TSource* const source, TTarget* const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
626 {
627  static_assert(sizeof(TSource) <= sizeof(TTarget), "Invalid data type!");
628  static_assert(tChannels >= 1u, "Invalid channel number!");
629 
630  ocean_assert(source != nullptr && target != nullptr);
631  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
632 
633  const unsigned int sourceStrideElements = width * tChannels + sourcePaddingElements;
634  const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
635 
636  for (unsigned int y = firstRow; y < firstRow + numberRows; ++y)
637  {
638  const TSource* const sourceRow = source + y * sourceStrideElements;
639  TTarget* const targetRow = target + y * targetStrideElements;
640 
641  for (unsigned int n = 0u; n < width * tChannels; ++n)
642  {
643  targetRow[n] = targetRow[n] + TTarget(sourceRow[n]);
644  }
645  }
646 }
647 
648 template <unsigned int tChannels>
649 void FrameMean::addToFrameIndividuallyBlock8BitPerChannelSubset(const uint8_t* source, const uint8_t* mask, unsigned int* target, unsigned int* denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, const unsigned int firstRow, const unsigned int numberRows)
650 {
651  static_assert(tChannels >= 1u, "Invalid channel number!");
652 
653  ocean_assert(source && mask && target && denominators);
654  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
655 
656  const unsigned int sourceStrideElements = width * tChannels + sourcePaddingElements;
657  const unsigned int maskStrideElements = width + maskPaddingElements;
658  const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
659  const unsigned int denominatorsStrideElements = width + denominatorsPaddingElements;
660 
661  target += firstRow * targetStrideElements;
662  denominators += firstRow * denominatorsStrideElements;
663 
664  source += firstRow * sourceStrideElements;
665  mask += firstRow * maskStrideElements;
666 
667  for (unsigned int rowIndex = firstRow; rowIndex < firstRow + numberRows; ++rowIndex)
668  {
669  const uint8_t* const sourceRowEnd = source + width * tChannels;
670 
671  while (source != sourceRowEnd)
672  {
673  ocean_assert(source < sourceRowEnd);
674 
675  if (*mask++ != nonMaskValue)
676  {
677  for (unsigned int n = 0u; n < tChannels; ++n)
678  {
679  target[n] += source[n];
680  }
681 
682  (*denominators)++;
683  }
684 
685  target += tChannels;
686  denominators++;
687  source += tChannels;
688  }
689 
690  target += targetPaddingElements;
691  denominators += denominatorsPaddingElements;
692 
693  source += sourcePaddingElements;
694  mask += maskPaddingElements;
695  }
696 }
697 
698 template <unsigned int tChannels>
699 void FrameMean::addToFrameIndividuallyZipped8BitPerChannelSubset(const uint8_t* source, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, const unsigned int firstRow, const unsigned int numberRows)
700 {
701  static_assert(tChannels >= 1u, "Invalid channel number!");
702 
703  ocean_assert(source && targetWithDenominator);
704  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
705 
706  targetWithDenominator += firstRow * width * (tChannels + 1u);
707 
708  source += firstRow * width * tChannels;
709 
710  const uint8_t* const sourceEnd = source + numberRows * width * tChannels;
711 
712  while (source != sourceEnd)
713  {
714  ocean_assert(source < sourceEnd);
715 
716  for (unsigned int n = 0u; n < tChannels; ++n)
717  *targetWithDenominator++ += *source++;
718 
719  (*targetWithDenominator++)++;
720  }
721 }
722 
723 template <unsigned int tChannels>
724 void FrameMean::addToFrameIndividuallyZipped8BitPerChannelSubset(const uint8_t* source, const uint8_t* mask, unsigned int* targetWithDenominator, const unsigned int width, const unsigned int height, const unsigned int firstRow, const unsigned int numberRows)
725 {
726  static_assert(tChannels >= 1u, "Invalid channel number!");
727 
728  ocean_assert(source && mask && targetWithDenominator);
729  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
730 
731  targetWithDenominator += firstRow * width * (tChannels + 1u);
732 
733  source += firstRow * width * tChannels;
734  mask += firstRow * width;
735 
736  const uint8_t* const sourceEnd = source + numberRows * width * tChannels;
737 
738  while (source != sourceEnd)
739  {
740  ocean_assert(source < sourceEnd);
741 
742  if (*mask++)
743  {
744  for (unsigned int n = 0u; n < tChannels; ++n)
745  {
746  targetWithDenominator[n] += source[n];
747  }
748 
749  targetWithDenominator[tChannels]++;
750  }
751 
752  targetWithDenominator += tChannels + 1u;
753  source += tChannels;
754  }
755 }
756 
757 template <typename TSource, typename TTarget, unsigned int tChannels>
758 void FrameMean::normalizeFrameSubset(const TSource* const source, TTarget* const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
759 {
760  static_assert(tChannels >= 1u, "Invalid channel number!");
761 
762  ocean_assert(source != nullptr && target != nullptr);
763  ocean_assert(denominator != 0u);
764  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
765 
766  const TSource denominator_2 = denominator / TSource(2);
767 
768  const unsigned int sourceStrideElements = width * tChannels + sourcePaddingElements;
769  const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
770 
771  for (unsigned int y = firstRow; y < firstRow + numberRows; ++y)
772  {
773  const TSource* const sourceRow = source + y * sourceStrideElements;
774  TTarget* const targetRow = target + y * targetStrideElements;
775 
776  for (unsigned int n = 0u; n < width * tChannels; ++n)
777  {
778  if (std::is_signed<TSource>::value)
779  {
780  targetRow[n] = TTarget(sourceRow[n] / denominator);
781  }
782  else
783  {
784  targetRow[n] = TTarget((sourceRow[n] + denominator_2) / denominator);
785  }
786  }
787  }
788 }
789 
790 template <unsigned int tChannels>
791 void FrameMean::normalizeFrameIndividually8BitPerChannelSubset(const unsigned int* source, const unsigned int* denominators, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, const unsigned int firstRow, const unsigned int numberRows)
792 {
793  static_assert(tChannels >= 1u, "Invalid channel number!");
794 
795  ocean_assert(source && denominators && target && zeroValue);
796  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
797 
798  typedef typename DataType<uint8_t, tChannels>::Type PixelType;
799 
800  target += firstRow * width * tChannels;
801  denominators += firstRow * width;
802  source += firstRow * width * tChannels;
803 
804  const unsigned int* const sourceEnd = source + numberRows * width * tChannels;
805 
806  while (source != sourceEnd)
807  {
808  ocean_assert(source < sourceEnd);
809 
810  if (*denominators)
811  {
812  const unsigned int denominator = *denominators;
813  const unsigned int denominator_2 = denominator / 2u;
814 
815  for (unsigned int n = 0u; n < tChannels; ++n)
816  {
817  target[n] = (uint8_t)((source[n] + denominator_2) / denominator);
818  }
819  }
820  else
821  {
822  *((PixelType*)target) = *((PixelType*)zeroValue);
823  }
824 
825  target += tChannels;
826  source += tChannels;
827 
828  denominators++;
829  }
830 }
831 
832 template <unsigned int tChannels>
833 void FrameMean::normalizeFrameIndividually8BitPerChannelSubset(const unsigned int* sourceWithDenominator, uint8_t* target, const unsigned int width, const unsigned int height, const uint8_t* zeroValue, const unsigned int firstRow, const unsigned int numberRows)
834 {
835  static_assert(tChannels >= 1u, "Invalid channel number!");
836 
837  ocean_assert(sourceWithDenominator && target && zeroValue);
838  ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
839 
840  typedef typename DataType<uint8_t, tChannels>::Type PixelType;
841 
842  target += firstRow * width * tChannels;
843  sourceWithDenominator += firstRow * width * (tChannels + 1u);
844 
845  const unsigned int* const sourceEnd = sourceWithDenominator + numberRows * width * (tChannels + 1u);
846 
847  while (sourceWithDenominator != sourceEnd)
848  {
849  ocean_assert(sourceWithDenominator < sourceEnd);
850 
851  if (sourceWithDenominator[tChannels])
852  {
853  const unsigned int denominator = sourceWithDenominator[tChannels];
854  const unsigned int denominator_2 = denominator / 2u;
855 
856  for (unsigned int n = 0u; n < tChannels; ++n)
857  {
858  target[n] = (uint8_t)((sourceWithDenominator[n] + denominator_2) / denominator);
859  }
860  }
861  else
862  {
863  *((PixelType*)target) = *((PixelType*)zeroValue);
864  }
865 
866  target += tChannels;
867  sourceWithDenominator += (tChannels + 1u);
868  }
869 }
870 
871 }
872 
873 }
874 
875 #endif // META_OCEAN_CV_FRAME_MEAN_H
static bool convert(const Frame &source, const FrameType::PixelFormat targetPixelFormat, const FrameType::PixelOrigin targetPixelOrigin, Frame &target, const bool forceCopy=true, Worker *worker=nullptr, const Options &options=Options())
Converts a frame with arbitrary dimension, pixel format and pixel origin into a frame with the same d...
@ CP_AVOID_COPY_IF_POSSIBLE
Tries to avoid copying the frame data whenever possible.
Definition: FrameConverter.h:96
This class implements functions allowing to determine e.g., the mean pixel value of a frame of a mean...
Definition: FrameMean.h:30
static void normalizeFrame(const TSource *const source, TTarget *const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Normalizes the pixels values of a given (accumulated frame) by a given denominator.
Definition: FrameMean.h:508
static void addToFrameSubset(const TSource *const source, TTarget *const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Adds the subset of individual pixel values of a given source frame to a target frame.
Definition: FrameMean.h:625
static void normalizeFrameSubset(const TSource *const source, TTarget *const target, const TSource denominator, unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Normalizes a subset of the pixels values of a given (accumulated frame) by a given denominator.
Definition: FrameMean.h:758
static void normalizeFrameIndividually8BitPerChannel(const unsigned int *source, const unsigned int *denominators, uint8_t *target, const unsigned int width, const unsigned int height, const uint8_t *zeroValue=nullptr, Worker *worker=nullptr)
Normalizes the pixels values of a given (accumulated frame) by individual denominator values.
Definition: FrameMean.h:526
static Frame meanFrame8BitPerChannel(FrameProviderInterface &frameProviderInterface, const FrameType::PixelFormat &targetPixelFormat, const unsigned int firstFrameIndex, const unsigned int lastFrameIndex, Worker *worker=nullptr, bool *abort=nullptr)
Determines the mean frame for a given set of frames.
Definition: FrameMean.h:371
static void normalizeFrameIndividually8BitPerChannelSubset(const unsigned int *source, const unsigned int *denominators, uint8_t *target, const unsigned int width, const unsigned int height, const uint8_t *zeroValue, const unsigned int firstRow, const unsigned int numberRows)
Normalizes a subset of the pixels values of a given (accumulated frame) by individual denominator val...
Definition: FrameMean.h:791
static void sumFrameSubset(const T *frame, const unsigned int width, TSum *sumValues, Lock *lock, const unsigned int framePaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Sums the pixel values in a subset of a given frame.
Definition: FrameMean.h:566
static Frame meanFrame(FrameProviderInterface &frameProviderInterface, const FrameType::PixelFormat &targetPixelFormat, const unsigned int firstFrameIndex, const unsigned int lastFrameIndex, Worker *worker=nullptr, bool *abort=nullptr)
Determines the mean frame for a given set of frames.
static void addToFrameIndividuallyBlock8BitPerChannelSubset(const uint8_t *source, const uint8_t *mask, unsigned int *target, unsigned int *denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, const unsigned int firstRow, const unsigned int numberRows)
Adds the subset of individual pixel values of a given source frame to a target frame (with denominato...
Definition: FrameMean.h:649
static void addToFrameIndividually8BitPerChannel(const uint8_t *source, const uint8_t *mask, unsigned int *target, unsigned int *denominators, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const unsigned int denominatorsPaddingElements, const uint8_t nonMaskValue, Worker *worker=nullptr)
Adds the individual pixel values of a given source frame to a target frame if the corresponding mask ...
Definition: FrameMean.h:454
static void addToFrameIndividuallyZipped8BitPerChannelSubset(const uint8_t *source, unsigned int *targetWithDenominator, const unsigned int width, const unsigned int height, const unsigned int firstRow, const unsigned int numberRows)
Adds the subset of individual pixel values of a given source frame to a target frame (with zipped den...
Definition: FrameMean.h:699
static bool addToFrameIndividually(const Frame &source, const Frame &mask, Frame &target, Frame &denominators, const uint8_t nonMaskValue, Worker *worker=nullptr)
Adds the individual pixel values of a given source frame to a target frame if the corresponding mask ...
static void meanValue(const T *frame, const unsigned int width, const unsigned int height, TMean *meanValues, const unsigned int framePaddingElements, Worker *worker=nullptr)
Determines the mean pixel value for a given frame.
Definition: FrameMean.h:327
static void addToFrame(const TSource *const source, TTarget *const target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Adds the individual pixel values of a given source frame to a target frame.
Definition: FrameMean.h:435
This class defines an abstract interface allowing to request frames from any kind of frame provider.
Definition: FrameProviderInterface.h:38
virtual bool isInitialized()=0
Returns whether the internal information of this interface has been initialized already and whether r...
virtual unsigned int synchronFrameNumberRequest(const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame number request.
virtual FrameType synchronFrameTypeRequest(const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame type request.
virtual void frameCacheRequest(const unsigned int index, const int range)
Invokes a suggestion to pre-load or to cache some frames that might be requested soon.
virtual FrameRef synchronFrameRequest(const unsigned int index, const double timeout=10.0, bool *abort=nullptr)=0
Invokes a synchronous frame request.
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
Template class allowing to define an array of data types.
Definition: DataType.h:27
This class implements Ocean's image class.
Definition: Frame.h:1760
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:4136
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition: Frame.h:4127
bool setValue(const uint8_t value, const unsigned int planeIndex=0u, const bool skipPaddingData=true)
Sets the memory of the frame to a specified byte value (the memory of one plane).
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:4010
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:3111
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition: Frame.h:3156
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3121
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1018
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3116
bool isValid() const
Returns whether this frame type is valid.
Definition: Frame.h:3181
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3141
This class implements a recursive lock object.
Definition: Lock.h:31
T TypePerformance
Definition of the data type for the next larger data type regarding performance.
Definition: DataType.h:261
This class provides basic numeric functionalities.
Definition: Numeric.h:57
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
bool isNull() const
Returns whether this object reference holds no internal object.
Definition: base/ObjectRef.h:390
This class implements an optional recursive scoped lock object locking the lock object only if it's d...
Definition: Lock.h:325
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15