8#ifndef META_OCEAN_CV_CV_UTILITIES_H
9#define META_OCEAN_CV_CV_UTILITIES_H
40 template <
unsigned int tSize>
62 template <
typename T,
unsigned int tChannels>
63 static inline void copyPixel(T*
const target,
const T*
const source);
71 template <
unsigned int tChannels>
72 static inline void copyPixel(uint8_t*
const target,
const uint8_t*
const source);
83 template <
typename T,
unsigned int tChannels>
84 static inline void copyPixel(T*
const target,
const T*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex);
94 template <
unsigned int tChannels>
95 static inline void copyPixel(uint8_t*
const target,
const uint8_t*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex);
112 template <
typename T,
unsigned int tChannels>
113 static inline void copyPixel(T*
const target,
const T*
const source,
const unsigned int xTarget,
const unsigned int yTarget,
const unsigned int xSource,
const unsigned int ySource,
const unsigned int targetWidth,
const unsigned int sourceWidth,
const unsigned int targetPaddingElements,
const unsigned int sourcePaddingElements);
129 template <
unsigned int tChannels>
130 static inline void copyPixel(uint8_t*
const target,
const uint8_t*
const source,
const unsigned int xTarget,
const unsigned int yTarget,
const unsigned int xSource,
const unsigned int ySource,
const unsigned int targetWidth,
const unsigned int sourceWidth,
const unsigned int targetPaddingElements,
const unsigned int sourcePaddingElements);
166 template <
typename T>
207 static inline int mirrorOffset(
const unsigned int index,
const unsigned int elements);
222 static OCEAN_FORCE_INLINE
int mirrorOffset(
const int index,
const unsigned int elements);
237 static OCEAN_FORCE_INLINE
unsigned int mirrorIndex(
const int index,
const unsigned int elements);
259 static Frame createCheckerboardImage(
const unsigned int width,
const unsigned int height,
const unsigned int horizontalElements,
const unsigned int verticalElements,
const unsigned int paddingElements,
const uint8_t bright = 0xFFu,
const uint8_t dark = 0x00u);
269 template <
typename T>
282 template <
typename T>
283 static void randomizMemory(T* data,
const unsigned int widthElements,
const unsigned int height,
const unsigned int paddingElements,
RandomGenerator& randomGenerator,
const bool limitedValueRange);
293 const static unsigned int size = 5u;
303 const static unsigned int size = 5u;
313 const static unsigned int size = 5u;
323 const static unsigned int size = 5u;
333 const static unsigned int size = 15u;
343 const static unsigned int size = 31u;
346template <
typename T,
unsigned int tChannels>
349 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
351 ocean_assert(target !=
nullptr && source !=
nullptr);
355 *((PixelType*)target) = *((
const PixelType*)source);
358template <
unsigned int tChannels>
361 copyPixel<uint8_t, tChannels>(target, source);
364template <
typename T,
unsigned int tChannels>
365inline void CVUtilities::copyPixel(T*
const target,
const T*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex)
367 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
369 ocean_assert(target !=
nullptr && source !=
nullptr);
373 *((PixelType*)target + targetIndex) = *((
const PixelType*)source + sourceIndex);
376template <
unsigned int tChannels>
377inline void CVUtilities::copyPixel(uint8_t*
const target,
const uint8_t*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex)
379 copyPixel<uint8_t, tChannels>(target, source, targetIndex, sourceIndex);
382template <
typename T,
unsigned int tChannels>
383inline void CVUtilities::copyPixel(T*
const target,
const T*
const source,
const unsigned int xTarget,
const unsigned int yTarget,
const unsigned int xSource,
const unsigned int ySource,
const unsigned int targetWidth,
const unsigned int sourceWidth,
const unsigned int targetPaddingElements,
const unsigned int sourcePaddingElements)
385 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
387 ocean_assert(target !=
nullptr && source !=
nullptr);
388 ocean_assert(xSource < sourceWidth);
389 ocean_assert(xTarget < targetWidth);
393 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
394 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
396 *((PixelType*)(target + yTarget * targetStrideElements) + xTarget) = *((
const PixelType*)(source + ySource * sourceStrideElements) + xSource);
399template <
unsigned int tChannels>
400inline void CVUtilities::copyPixel(uint8_t*
const target,
const uint8_t*
const source,
const unsigned int xTarget,
const unsigned int yTarget,
const unsigned int xSource,
const unsigned int ySource,
const unsigned int targetWidth,
const unsigned int sourceWidth,
const unsigned int targetPaddingElements,
const unsigned int sourcePaddingElements)
402 copyPixel<uint8_t, tChannels>(target, source, xTarget, yTarget, xSource, ySource, targetWidth, sourceWidth, targetPaddingElements, sourcePaddingElements);
410 ocean_assert(minValue <= maxValue);
416 for (
unsigned int y = 0u; y < frame.
height(); ++y)
418 uint8_t* data = frame.
row<uint8_t>(y);
420 for (
unsigned int x = 0u; x < elementsInRow; ++x)
422 data[x] = uint8_t(
RandomI::random(localRandomGenerator, (
unsigned int)minValue, (
unsigned int)maxValue));
432 ocean_assert(minValue <= maxValue);
438 for (
unsigned int y = 0u; y < frame.
height(); ++y)
440 float* data = frame.
row<
float>(y);
442 for (
unsigned int x = 0u; x < elementsInRow; ++x)
461 if ((
unsigned int)index < elements)
463 return (
unsigned int)(index);
468 const unsigned int result = (
unsigned int)(-index) - 1u;
470 ocean_assert(result < elements);
476 const unsigned int result = elements * 2u - (
unsigned int)(index) - 1u;
478 ocean_assert(result < elements);
This class implements Computer Vision utility functions.
Definition CVUtilities.h:33
static Frame randomizedBinaryMask(const unsigned int width, const unsigned int height, const uint8_t maskValue, RandomGenerator *randomGenerator=nullptr)
Creates an 8 bit frame with a random binary mask, the optional padding area will be filled with rando...
static Frame visualizeDistortion(const PinholeCamera &pinholeCamera, const bool undistort, const unsigned int horizontalBins, const unsigned int verticalBins, Worker *worker=nullptr)
Deprecated.
static OCEAN_FORCE_INLINE unsigned int mirrorIndex(const int index, const unsigned int elements)
Returns the mirrored index for a given index.
Definition CVUtilities.h:459
static bool isPaddingMemoryIdentical(const Frame &frameA, const Frame &frameB)
Returns whether the padding memory at the end of each image row is identical in two given frames.
static void randomizMemory(T *data, const unsigned int widthElements, const unsigned int height, const unsigned int paddingElements, RandomGenerator &randomGenerator, const bool limitedValueRange)
Randomizes a given memory block.
static FrameType::PixelFormats definedPixelFormats(const FrameType::PixelFormats &genericPixelFormats=FrameType::PixelFormats())
Returns all defined pixel formats.
static int mirrorOffset(const unsigned int index, const unsigned int elements)
Deprecated.
Definition CVUtilities.h:449
static Frame createCheckerboardImage(const unsigned int width, const unsigned int height, const unsigned int horizontalElements, const unsigned int verticalElements, const unsigned int paddingElements, const uint8_t bright=0xFFu, const uint8_t dark=0x00u)
Creates an image with a checkerboard pattern with pixel format FORMAT_Y8 with a dark elements in the ...
static void copyPixel(T *const target, const T *const source)
Copies the pixel value from one pixel to another.
Definition CVUtilities.h:347
static bool isBorderZero(const Frame &frame)
Returns whether all border pixels of an image are set to zero.
static Frame randomizedFrame(const FrameType &frameType, RandomGenerator *randomGenerator=nullptr, const bool limitedValueRange=false)
Returns a randomized frame for a given frame type, the optional padding area will be filled with rand...
static bool isBorderZero(const Frame &frame)
Returns whether all border pixels of an image are set to zero.
static void randomizeFrame(Frame &frame, const bool skipPaddingArea=true, RandomGenerator *randomGenerator=nullptr, const bool limitedValueRange=false)
Creates randomized data for a given frame.
static void randomizeFrame(Frame &frame, const T minValue, const T maxValue, const bool skipPaddingArea=true, RandomGenerator *randomGenerator=nullptr)
Creates randomized data for a given frame while the randomized data will be in a specific value range...
This class implements Ocean's image class.
Definition Frame.h:1808
unsigned int strideElements(const unsigned int planeIndex=0u) const
Returns the number of elements within one row, including optional padding at the end of a row for a s...
Definition Frame.h:4141
T * row(const unsigned int y, const unsigned int planeIndex=0u)
Returns the pointer to the pixel data of a specific row.
Definition Frame.h:4260
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4531
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3170
std::vector< PixelFormat > PixelFormats
Definition of a vector holding pixel formats.
Definition Frame.h:1040
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
@ DT_SIGNED_FLOAT_32
Signed 32 bit float data type (float).
Definition Frame.h:59
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3200
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition Frame.h:3190
static bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Checks whether a given pixel format is a specific layout regarding data channels and data type.
Definition Frame.h:3435
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
static unsigned int random(const unsigned int maxValue)
Returns one random integer value with specified maximum value.
static T scalar(const T lower, const T upper)
Returns a random number between two borders.
Definition Random.h:388
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
This struct is a helper class allowing to determine the next smaller tracking patch for a given patch...
Definition CVUtilities.h:42
Default definition of a type with tBytes bytes.
Definition DataType.h:32