Mask
class Mask : NSObject, NSCopying
The wrapper class for MediaPipe segmentation masks.
Masks are stored as UInt8 *
or float *
objects.
Every mask has an underlying type which can be accessed using dataType
. You can access the
mask as any other type using the appropriate properties. For example, if the underlying type is
uInt8
, in addition to accessing the mask using uint8Data
, you can access float32Data
to get
the 32 bit float data (with values ranging from 0.0 to 1.0). The first time you access the data
as a type different from the underlying type, an expensive type conversion is performed.
Subsequent accesses return a pointer to the memory location for the same type converted array. As
type conversions can be expensive, it is recommended to limit the accesses to data of types
different from the underlying type.
Masks that are returned from a MediaPipe Tasks are owned by by the underlying C++ Task. If you
need to extend the lifetime of these objects, you can invoke the copy()
method.
-
The width of the mask.
Declaration
Swift
var width: Int { get }
-
The height of the mask.
Declaration
Swift
var height: Int { get }
-
The data type of the mask.
Declaration
Swift
var dataType: MaskDataType { get }
-
The pointer to the memory location where the underlying mask as a single channel
UInt8
array is stored. Uint8 values use the full value range and range from 0 to 255.Declaration
Swift
var uint8Data: UnsafePointer<UInt8> { get }
-
The pointer to the memory location where the underlying mask as a single channel float 32 array is stored. Float values range from 0.0 to 1.0.
Declaration
Swift
var float32Data: UnsafePointer<Float> { get }
-
Initializes an
Mask
object of typeuInt8
with the givenUInt8*
data, width and height.If
shouldCopy
is set totrue
, the newly createdMask
stores a reference to a deep copieduint8Data
. Since deep copies are expensive, it is recommended to not setshouldCopy
unless theMask
must outlive the passed inuint8Data
.Declaration
Swift
init?(uInt8Data uint8Data: UnsafePointer<UInt8>, width: Int, height: Int, shouldCopy: Bool)
Parameters
uint8Data
A pointer to the memory location of the
UInt8
data array.width
The width of the mask.
height
The height of the mask.
shouldCopy
The height of the mask.
Return Value
A new
Mask
instance with the givenUInt8*
data, width and height. -
Initializes an
Mask
object of typefloat32
with the givenfloat*
data, width and height.If
shouldCopy
is set totrue
, the newly createdMask
stores a reference to a deep copiedfloat32Data
. Since deep copies are expensive, it is recommended to not setshouldCopy
unless theMask
must outlive the passed infloat32Data
.Declaration
Swift
init?(float32Data: UnsafePointer<Float>, width: Int, height: Int, shouldCopy: Bool)
Parameters
float32Data
A pointer to the memory location of the
float
data array.width
The width of the mask.
height
The height of the mask.
Return Value
A new
Mask
instance with the givenfloat*
data, width and height. -
Unavailable.
-
Undocumented