Ocean
Ocean::CV::CVUtilities Class Reference

This class implements Computer Vision utility functions. More...

Data Structures

struct  SmallerPatchSize
 This struct is a helper class allowing to determine the next smaller tracking patch for a given patch size. More...
 
struct  SmallerPatchSize< 15u >
 Specialization of the helper struct. More...
 
struct  SmallerPatchSize< 31u >
 Specialization of the helper struct. More...
 
struct  SmallerPatchSize< 5u >
 Specialization of the helper struct. More...
 
struct  SmallerPatchSize< 63u >
 Specialization of the helper struct. More...
 
struct  SmallerPatchSize< 7u >
 Specialization of the helper struct. More...
 
struct  SmallerPatchSize< 9u >
 Specialization of the helper struct. More...
 

Public Member Functions

template<>
void randomizeFrame (Frame &frame, const uint8_t minValue, const uint8_t maxValue, const bool skipPaddingArea, RandomGenerator *randomGenerator)
 
template<>
void randomizeFrame (Frame &frame, const float minValue, const float maxValue, const bool skipPaddingArea, RandomGenerator *randomGenerator)
 

Static Public Member Functions

static FrameType::PixelFormats definedPixelFormats (const FrameType::PixelFormats &genericPixelFormats=FrameType::PixelFormats())
 Returns all defined pixel formats. More...
 
template<typename T , unsigned int tChannels>
static void copyPixel (T *const target, const T *const source)
 Copies the pixel value from one pixel to another. More...
 
template<unsigned int tChannels>
static void copyPixel (uint8_t *const target, const uint8_t *const source)
 Copies the pixel value from one pixel to another. More...
 
template<typename T , unsigned int tChannels>
static void copyPixel (T *const target, const T *const source, const unsigned int targetIndex, const unsigned int sourceIndex)
 Copies the pixel value from one pixel to another. More...
 
template<unsigned int tChannels>
static void copyPixel (uint8_t *const target, const uint8_t *const source, const unsigned int targetIndex, const unsigned int sourceIndex)
 Copies the pixel value from one pixel to another. More...
 
template<typename T , unsigned int tChannels>
static 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)
 Copies the pixel value from one pixel to another. More...
 
template<unsigned int tChannels>
static 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)
 Copies the pixel value from one pixel to another. More...
 
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. More...
 
static void randomizeFrame (Frame &frame, const bool skipPaddingArea=true, RandomGenerator *randomGenerator=nullptr, const bool limitedValueRange=false)
 Creates randomized data for a given frame. More...
 
template<typename T >
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. More...
 
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 random (not binary) noise. More...
 
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 random (not binary) noise. More...
 
static bool isBorderZero (const Frame &frame)
 Returns whether all border pixels of an image are set to zero. More...
 
static int mirrorOffset (const unsigned int index, const unsigned int elements)
 Deprecated. More...
 
static OCEAN_FORCE_INLINE int mirrorOffset (const int index, const unsigned int elements)
 Returns the mirrored correction offset for a given index. More...
 
static OCEAN_FORCE_INLINE unsigned int mirrorIndex (const int index, const unsigned int elements)
 Returns the mirrored index for a given index. More...
 
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. More...
 
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 upper left corner. More...
 

Static Protected Member Functions

template<typename T >
static bool isBorderZero (const Frame &frame)
 Returns whether all border pixels of an image are set to zero. More...
 
template<typename T >
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. More...
 

Detailed Description

This class implements Computer Vision utility functions.

Member Function Documentation

◆ copyPixel() [1/6]

template<typename T , unsigned int tChannels>
void Ocean::CV::CVUtilities::copyPixel ( T *const  target,
const T *const  source 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target pixel, must be valid
sourceThe source pixel, must be valid
Template Parameters
TThe data type of each pixel channel
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ copyPixel() [2/6]

template<typename T , unsigned int tChannels>
void Ocean::CV::CVUtilities::copyPixel ( T *const  target,
const T *const  source,
const unsigned int  targetIndex,
const unsigned int  sourceIndex 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target image, must be valid
sourceThe source image, must be valid
targetIndexIndex of the pixel inside the target frame, the index is determined for a pixel (x, y) by (y * width + x), frame channels are handled inside, with range [0, width * height - 1]
sourceIndexIndex of the pixel inside the source frame, the index is determined for a pixel (x, y) by (y * width + x), frame channels are handled inside, with range [0, width * height - 1]
Template Parameters
TThe data type of each pixel channel
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ copyPixel() [3/6]

template<typename T , unsigned int tChannels>
void Ocean::CV::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 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target image, must be valid
sourceThe source image, must be valid
xTargetHorizontal target position, in pixel, with range [0, targetWidth - 1]
yTargetVertical target position, in pixel, with range [0, targetHeight - 1]
xSourceHorizontal source position, in pixel, with range [0, sourceWidth - 1]
ySourceVertical source position, in pixel, with range [0, sourceHeight - 1]
targetWidthWidth of the target frame, in pixel, with range [1, infinity)
sourceWidthWidth of the source frame, in pixel, with range [1, infinity)
targetPaddingElementsThe number of padding elements at the end of each target row, in elements, with range [0, infinity)
sourcePaddingElementsThe number of padding elements at the end of each target row, in elements, with range [0, infinity)
Template Parameters
TThe data type of each pixel channel
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ copyPixel() [4/6]

template<unsigned int tChannels>
void Ocean::CV::CVUtilities::copyPixel ( uint8_t *const  target,
const uint8_t *const  source 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target pixel, must be valid
sourceThe source pixel, must be valid
Template Parameters
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ copyPixel() [5/6]

template<unsigned int tChannels>
void Ocean::CV::CVUtilities::copyPixel ( uint8_t *const  target,
const uint8_t *const  source,
const unsigned int  targetIndex,
const unsigned int  sourceIndex 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target image, must be valid
sourceThe source image, must be valid
targetIndexIndex of the pixel inside the target frame, the index is determined for a pixel (x, y) by (y * width + x), frame channels are handled inside, with range [0, width * height - 1]
sourceIndexIndex of the pixel inside the source frame, the index is determined for a pixel (x, y) by (y * width + x), frame channels are handled inside, with range [0, width * height - 1]
Template Parameters
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ copyPixel() [6/6]

template<unsigned int tChannels>
void Ocean::CV::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 
)
inlinestatic

Copies the pixel value from one pixel to another.

Parameters
targetThe target image, must be valid
sourceThe source image, must be valid
xTargetHorizontal target position, in pixel, with range [0, targetWidth - 1]
yTargetVertical target position, in pixel, with range [0, targetHeight - 1]
xSourceHorizontal source position, in pixel, with range [0, sourceWidth - 1]
ySourceVertical source position, in pixel, with range [0, sourceHeight - 1]
targetWidthWidth of the target frame, in pixel, with range [1, infinity)
sourceWidthWidth of the source frame, in pixel, with range [1, infinity)
targetPaddingElementsThe number of padding elements at the end of each target row, in elements, with range [0, infinity)
sourcePaddingElementsThe number of padding elements at the end of each target row, in elements, with range [0, infinity)
Template Parameters
tChannelsSpecified the number of pixel channels, with range [1, infinity)

◆ createCheckerboardImage()

static Frame Ocean::CV::CVUtilities::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 
)
static

Creates an image with a checkerboard pattern with pixel format FORMAT_Y8 with a dark elements in the upper left corner.

Parameters
widthThe width of the resulting image, with range [horizontalElements, infinity), must be a multiple of 'horizontalElements'
heightThe height of the resulting image, with range [verticalElements, infinity), must be a multiple of 'verticalElements'
horizontalElementsThe number of horizontal checkerboard elements, with range [1, infinity)
verticalElementsThe number of vertical checkerboard elements, with range [1, infinity)
paddingElementsThe number of padding elements at the end of each image row, in elements, with range [0, infinity)
brightThe color value of the bright elements
darkThe color value of the dark elements
Returns
The resulting checkerboard image

◆ definedPixelFormats()

static FrameType::PixelFormats Ocean::CV::CVUtilities::definedPixelFormats ( const FrameType::PixelFormats genericPixelFormats = FrameType::PixelFormats())
static

Returns all defined pixel formats.

Parameters
genericPixelFormatsOptional custom generic pixel formats which will be added to the resulting pixel formats
Returns
Ocean's defined pixel formats

◆ isBorderZero() [1/2]

static bool Ocean::CV::CVUtilities::isBorderZero ( const Frame frame)
static

Returns whether all border pixels of an image are set to zero.

Parameters
frameThe frame to test, must be valid
Returns
True, if so

◆ isBorderZero() [2/2]

template<typename T >
static bool Ocean::CV::CVUtilities::isBorderZero ( const Frame frame)
staticprotected

Returns whether all border pixels of an image are set to zero.

Parameters
frameThe frame to test, must be valid
Returns
True, if so
Template Parameters
TThe data type of the pixel elements

◆ isPaddingMemoryIdentical()

static bool Ocean::CV::CVUtilities::isPaddingMemoryIdentical ( const Frame frameA,
const Frame frameB 
)
static

Returns whether the padding memory at the end of each image row is identical in two given frames.

In case both frames do not have a padding memory, True is returned.

Parameters
frameAThe first frame top be compared, must be valid
frameBThe second frame to be compared, can have a different width as frameA, must be valid
Returns
True, if so

◆ mirrorIndex()

OCEAN_FORCE_INLINE unsigned int Ocean::CV::CVUtilities::mirrorIndex ( const int  index,
const unsigned int  elements 
)
static

Returns the mirrored index for a given index.

The mirrored index is calculated as follows:

                          |<----------------------- valid value range -------------------------->|

index:          -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7,  ... elements - 3, elements - 2, elements - 1, elements + 0, elements + 1
mirrored index:  2   1   0  0  1  2  3  4  5  6  7       elements - 3  elements - 2  elements - 1  elements - 1  elements - 2
Parameters
indexThe index for which the mirrored index will be returned, with range [-elements / 2, elements + elements / 2]
elementsThe number of maximal elements, with range [1, infinity)
Returns
The resulting mirrored index, with range [0, elements - 1]

◆ mirrorOffset() [1/2]

OCEAN_FORCE_INLINE int Ocean::CV::CVUtilities::mirrorOffset ( const int  index,
const unsigned int  elements 
)
static

Returns the mirrored correction offset for a given index.

The correction offset is calculated as follows:

                          |<----------------------- valid value range -------------------------->|

index:          -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7,  ... elements - 3, elements - 2, elements - 1, elements, elements + 1
result:          5   3   1  0  0  0  0  0  0  0  0                  0             0             0  -1        -3
Parameters
indexThe index for which the correction offset will be returned, with range [-elements / 2, elements + elements / 2]
elementsThe number of maximal elements, with range [1, infinity)
Returns
The resulting correction offset, with range (-infinity, infinity)

◆ mirrorOffset() [2/2]

int Ocean::CV::CVUtilities::mirrorOffset ( const unsigned int  index,
const unsigned int  elements 
)
inlinestatic

Deprecated.

Returns the mirrored correction offset for a given index.

Parameters
indexIndex to return the correction offset for
elementsNumber of maximal elements
Returns
The resulting correction offset, with range (-infinity, infinity)

◆ randomizedBinaryMask()

static Frame Ocean::CV::CVUtilities::randomizedBinaryMask ( const unsigned int  width,
const unsigned int  height,
const uint8_t  maskValue,
RandomGenerator randomGenerator = nullptr 
)
static

Creates an 8 bit frame with a random binary mask, the optional padding area will be filled with random (not binary) noise.

The resulting mask may contain random padding elements.
The timestamp will be randomized as well.

Parameters
widthThe width of the resulting frame in pixel, with range [1, infinity)
heightThe height of the resulting frame in pixel, with range [1, infinity)
maskValueThe value of mask pixels, 0xFF - maskValue will be the value of non-mask pixels, with range [0x00, 0xFF]
randomGeneratorRandom generator object to be used

◆ randomizedFrame()

static Frame Ocean::CV::CVUtilities::randomizedFrame ( const FrameType frameType,
RandomGenerator randomGenerator = nullptr,
const bool  limitedValueRange = false 
)
static

Returns a randomized frame for a given frame type, the optional padding area will be filled with random (not binary) noise.

The resulting frame may contain random padding elements.
Integer pixel formats as well as float pixel formats will receive values in the range [0, 255] or [-128, 127] for each pixel and channel if 'limitedValueRange == true'
The timestamp will be randomized as well.

Parameters
frameTypeThe frame type for which the randomized frame will be created, may be invalid
randomGeneratorOptional explicit random generator to be used, nullptr to use any
limitedValueRangeTrue, to use a value range of [0, 255] and [-128, 127] independently of the actual element data type; False, to use the full value range
Returns
The randomized frame, invalid if frameType is invalid

◆ randomizeFrame() [1/4]

static void Ocean::CV::CVUtilities::randomizeFrame ( Frame frame,
const bool  skipPaddingArea = true,
RandomGenerator randomGenerator = nullptr,
const bool  limitedValueRange = false 
)
static

Creates randomized data for a given frame.

Integer pixel formats as well as float pixel formats will receive values in the range [0, 255] or [-128, 127] for each pixel and channel if 'limitedValueRange == true'

Parameters
frameThe frame to fill with randomized data, may be invalid
skipPaddingAreaTrue, to leave elements within the padding area untouched; False, to randomize the entire memory
randomGeneratorOptional explicit random generator to be used, nullptr to use any
limitedValueRangeTrue, to use a value range of [0, 255] and [-128, 127] independently of the actual element data type; False, to use the full value range

◆ randomizeFrame() [2/4]

template<>
void Ocean::CV::CVUtilities::randomizeFrame ( Frame frame,
const float  minValue,
const float  maxValue,
const bool  skipPaddingArea,
RandomGenerator randomGenerator 
)
inline

◆ randomizeFrame() [3/4]

template<typename T >
static void Ocean::CV::CVUtilities::randomizeFrame ( Frame frame,
const T  minValue,
const T  maxValue,
const bool  skipPaddingArea = true,
RandomGenerator randomGenerator = nullptr 
)
static

Creates randomized data for a given frame while the randomized data will be in a specific value range.

The pixel format of the frame must be generic (a pixel format with zipped channel layout).

Parameters
frameThe frame to fill with randomized data, may be invalid
minValueThe minimal random value, with range (-infinity, maxValue]
maxValueThe maximal random value, with range [minValue, infinity)
skipPaddingAreaTrue, to leave elements within the padding area untouched; False, to randomize the entire memory
randomGeneratorOptional explicit random generator to be used, nullptr to use any
Template Parameters
TThe data type of each pixel element, e.g., 'unsigned char' or 'float'

◆ randomizeFrame() [4/4]

template<>
void Ocean::CV::CVUtilities::randomizeFrame ( Frame frame,
const uint8_t  minValue,
const uint8_t  maxValue,
const bool  skipPaddingArea,
RandomGenerator randomGenerator 
)
inline

◆ randomizMemory()

template<typename T >
static void Ocean::CV::CVUtilities::randomizMemory ( T *  data,
const unsigned int  widthElements,
const unsigned int  height,
const unsigned int  paddingElements,
RandomGenerator randomGenerator,
const bool  limitedValueRange 
)
staticprotected

Randomizes a given memory block.

Parameters
dataThe memory block to randomize, must be valid
widthElementsThe width of the memory block, in elements, with range [1, infinity)
heightThe height of the memory block, in pixels, with range [1, infinity)
paddingElementsThe number of padding elements at the end of each block row, in elements, with range [0, infinity)
randomGeneratorThe random generator to be used
limitedValueRangeTrue, to use a value range of [0, 255] and [-128, 127] independently of the actual element data type; False, to use the full value range
Template Parameters
TThe data type of each element

◆ visualizeDistortion()

static Frame Ocean::CV::CVUtilities::visualizeDistortion ( const PinholeCamera pinholeCamera,
const bool  undistort,
const unsigned int  horizontalBins,
const unsigned int  verticalBins,
Worker worker = nullptr 
)
static

Visualizes the distortion of a camera.

Parameters
pinholeCameraThe pinhole camera profile for which the distortion/undistortion is visualized
undistortTrue, to visualize the undistorted frame, otherwise the distorted frame is visualized
horizontalBinsNumber of horizontal bins, with range [1, pinholeCamera.width() / 2u)
verticalBinsNumber of vertical bins, with range [1, pinholeCamera.height() / 2u)
workerOptional worker object to distribute the computation
Returns
Resulting distortion frame

The documentation for this class was generated from the following file: