8 #ifndef META_OCEAN_CV_MASK_ANALYZER_H
9 #define META_OCEAN_CV_MASK_ANALYZER_H
43 static PixelBoundingBox detectBoundingBox(
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const uint8_t nonMaskPixel,
const unsigned int maskPaddingElements);
56 static PixelBoundingBox detectBoundingBox(
const uint8_t*
const mask,
const unsigned int width,
const unsigned int height,
const PixelBoundingBox& rough,
const unsigned int maxUncertainty,
const uint8_t nonMaskPixel = 0xFFu,
const unsigned int maskPaddingElements = 0u);
72 static PixelBoundingBox detectOpaqueBoundingBox(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int alphaChannelIndex,
const unsigned int channels,
const T fullTransparentValue,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
93 static inline bool hasValue(
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const uint8_t value,
const unsigned int maskPaddingElements,
const PixelBoundingBox& boundingBox =
CV::PixelBoundingBox());
115 template <
typename T>
116 static void detectOpaqueBoundingBoxSubset(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int alphaChannelIndex,
const unsigned int channels,
const T fullTransparentValue,
const unsigned int framePaddingElements,
unsigned int* left,
unsigned int* top,
unsigned int* right,
unsigned int* bottom,
Lock* lock,
const unsigned int firstRow,
const unsigned int numberRows);
119 template <
typename T>
122 ocean_assert(frame !=
nullptr);
123 ocean_assert(channels != 0u);
124 ocean_assert(alphaChannelIndex < channels);
126 unsigned int left = (
unsigned int)(-1);
127 unsigned int top = (
unsigned int)(-1);
128 unsigned int right = 0u;
129 unsigned int bottom = 0u;
134 worker->
executeFunction(
Worker::Function::createStatic(&MaskAnalyzer::detectOpaqueBoundingBoxSubset<T>, frame, width, height, alphaChannelIndex, channels, fullTransparentValue, framePaddingElements, &left, &top, &right, &bottom, &lock, 0u, 0u), 0u, height, 12u, 13u, 20u);
138 detectOpaqueBoundingBoxSubset<T>(frame, width, height, alphaChannelIndex, channels, fullTransparentValue, framePaddingElements, &left, &top, &right, &bottom,
nullptr, 0u, height);
144 template <
typename T>
145 void MaskAnalyzer::detectOpaqueBoundingBoxSubset(
const T* frame,
const unsigned int width,
const unsigned int height,
const unsigned int alphaChannelIndex,
const unsigned int channels,
const T fullTransparentValue,
const unsigned int framePaddingElements,
unsigned int* left,
unsigned int* top,
unsigned int* right,
unsigned int* bottom,
Lock* lock,
const unsigned int firstRow,
const unsigned int numberRows)
147 ocean_assert(frame !=
nullptr);
148 ocean_assert(alphaChannelIndex < channels);
149 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
151 const unsigned int frameStrideElements = width * channels + framePaddingElements;
153 unsigned int localLeft = (
unsigned int)(-1);
154 unsigned int localRight = 0u;
155 unsigned int localTop = (
unsigned int)(-1);
156 unsigned int localBottom = 0u;
158 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
160 const T* frameRow = frame + y * frameStrideElements + alphaChannelIndex;
162 for (
unsigned int x = 0u; x < width; ++x)
164 if (*frameRow != fullTransparentValue)
187 frameRow += channels;
193 *left = min(*left, localLeft);
194 *top = min(*top, localTop);
196 *right = max(*right, localRight);
197 *bottom = max(*bottom, localBottom);
200 inline bool MaskAnalyzer::hasValue(
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const uint8_t value,
const unsigned int maskPaddingElements,
const PixelBoundingBox& boundingBox)
202 ocean_assert(mask !=
nullptr && width != 0u && height != 0u);
This class implements basic maks analyzing functions.
Definition: MaskAnalyzer.h:30
static PixelBoundingBox detectBoundingBox(const uint8_t *mask, const unsigned int width, const unsigned int height, const uint8_t nonMaskPixel, const unsigned int maskPaddingElements)
Detects the smallest axis-aligned bounding box enclosing all isolated mask islands in a binary (but 8...
static PixelBoundingBox detectOpaqueBoundingBox(const Frame &frame, const bool transparentIs0xFF, Worker *worker=nullptr)
Detects the smallest bounding box of opaque pixels in a given frame.
static PixelBoundingBox detectBoundingBox(const uint8_t *const mask, const unsigned int width, const unsigned int height, const PixelBoundingBox &rough, const unsigned int maxUncertainty, const uint8_t nonMaskPixel=0xFFu, const unsigned int maskPaddingElements=0u)
Detects the smallest axis-aligned bounding box enclosing all isolated mask islands inside a given mas...
static bool hasValue(const uint8_t *mask, const unsigned int width, const unsigned int height, const uint8_t value, const unsigned int maskPaddingElements, const PixelBoundingBox &boundingBox=CV::PixelBoundingBox())
Returns whether a mask frame has at least one pixel with a specific mask value.
Definition: MaskAnalyzer.h:200
static PixelBoundingBox detectOpaqueBoundingBox(const T *frame, const unsigned int width, const unsigned int height, const unsigned int alphaChannelIndex, const unsigned int channels, const T fullTransparentValue, const unsigned int framePaddingElements, Worker *worker=nullptr)
Detects the smallest bounding box enclosing all opaque pixels in a given frame.
Definition: MaskAnalyzer.h:120
static void detectOpaqueBoundingBoxSubset(const T *frame, const unsigned int width, const unsigned int height, const unsigned int alphaChannelIndex, const unsigned int channels, const T fullTransparentValue, const unsigned int framePaddingElements, unsigned int *left, unsigned int *top, unsigned int *right, unsigned int *bottom, Lock *lock, const unsigned int firstRow, const unsigned int numberRows)
Detects the smallest bounding box enclosing all opaque pixels in a subset of a given frame.
Definition: MaskAnalyzer.h:145
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
unsigned int width() const
Returns the width (the number of horizontal including pixels) of this bounding box.
Definition: PixelBoundingBox.h:482
bool isValid() const
Returns whether this bounding box covers a valid pixel area.
Definition: PixelBoundingBox.h:577
T top() const
Returns the top (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:423
unsigned int height() const
Returns the height (the number of vertical including pixels) of this bounding box.
Definition: PixelBoundingBox.h:489
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
This class implements Ocean's image class.
Definition: Frame.h:1792
typename Ocean::DataType< T, tChannels >::Type PixelType
Definition of a data type storing all channel values of one pixel in an array.
Definition: Frame.h:2311
Frame subFrame(const unsigned int subFrameLeft, const unsigned int subFrameTop, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CopyMode copyMode=CM_USE_KEEP_LAYOUT) const
Returns a sub-frame of this frame.
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition: Frame.h:1801
bool containsValue(const PixelType< T, tPlaneChannels > &planePixelValue, const unsigned int planeIndex=0u) const
Returns whether the frame (one plane) contains a specified pixel value.
Definition: Frame.h:3924
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition: Frame.h:594
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
This class implements a recursive lock object.
Definition: Lock.h:31
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.
PixelBoundingBoxT< unsigned int > PixelBoundingBox
Definition of the default PixelBoundingBox object with data type allowing only positive coordinate va...
Definition: PixelBoundingBox.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15