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);
163 template <
typename T>
204 static inline int mirrorOffset(
const unsigned int index,
const unsigned int elements);
219 static OCEAN_FORCE_INLINE
int mirrorOffset(
const int index,
const unsigned int elements);
234 static OCEAN_FORCE_INLINE
unsigned int mirrorIndex(
const int index,
const unsigned int elements);
256 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);
266 template <
typename T>
279 template <
typename T>
280 static void randomizMemory(T* data,
const unsigned int widthElements,
const unsigned int height,
const unsigned int paddingElements,
RandomGenerator& randomGenerator,
const bool limitedValueRange);
290 const static unsigned int size = 5u;
300 const static unsigned int size = 5u;
310 const static unsigned int size = 5u;
320 const static unsigned int size = 5u;
330 const static unsigned int size = 15u;
340 const static unsigned int size = 31u;
343template <
typename T,
unsigned int tChannels>
346 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
348 ocean_assert(target !=
nullptr && source !=
nullptr);
352 *((PixelType*)target) = *((
const PixelType*)source);
355template <
unsigned int tChannels>
358 copyPixel<uint8_t, tChannels>(target, source);
361template <
typename T,
unsigned int tChannels>
362inline void CVUtilities::copyPixel(T*
const target,
const T*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex)
364 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
366 ocean_assert(target !=
nullptr && source !=
nullptr);
370 *((PixelType*)target + targetIndex) = *((
const PixelType*)source + sourceIndex);
373template <
unsigned int tChannels>
374inline void CVUtilities::copyPixel(uint8_t*
const target,
const uint8_t*
const source,
const unsigned int targetIndex,
const unsigned int sourceIndex)
376 copyPixel<uint8_t, tChannels>(target, source, targetIndex, sourceIndex);
379template <
typename T,
unsigned int tChannels>
380inline 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)
382 static_assert(tChannels != 0u,
"The specified number of channels is not supported!");
384 ocean_assert(target !=
nullptr && source !=
nullptr);
385 ocean_assert(xSource < sourceWidth);
386 ocean_assert(xTarget < targetWidth);
390 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
391 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
393 *((PixelType*)(target + yTarget * targetStrideElements) + xTarget) = *((
const PixelType*)(source + ySource * sourceStrideElements) + xSource);
396template <
unsigned int tChannels>
397inline 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)
399 copyPixel<uint8_t, tChannels>(target, source, xTarget, yTarget, xSource, ySource, targetWidth, sourceWidth, targetPaddingElements, sourcePaddingElements);
407 ocean_assert(minValue <= maxValue);
413 for (
unsigned int y = 0u; y < frame.
height(); ++y)
415 uint8_t* data = frame.
row<uint8_t>(y);
417 for (
unsigned int x = 0u; x < elementsInRow; ++x)
419 data[x] = uint8_t(
RandomI::random(localRandomGenerator, (
unsigned int)minValue, (
unsigned int)maxValue));
429 ocean_assert(minValue <= maxValue);
435 for (
unsigned int y = 0u; y < frame.
height(); ++y)
437 float* data = frame.
row<
float>(y);
439 for (
unsigned int x = 0u; x < elementsInRow; ++x)
458 if ((
unsigned int)index < elements)
460 return (
unsigned int)(index);
465 const unsigned int result = (
unsigned int)(-index) - 1u;
467 ocean_assert(result < elements);
473 const unsigned int result = elements * 2u - (
unsigned int)(index) - 1u;
475 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)
Visualizes the distortion of a camera.
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:456
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:446
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:344
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:4138
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:4257
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4528
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