MediaPipeTasksVision Framework Reference

MPPMask


@interface MPPMask : 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

    Objective-C

    @property (nonatomic, readonly) NSInteger width;
  • The height of the mask.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSInteger height;
  • The data type of the mask.

    Declaration

    Objective-C

    @property (nonatomic, readonly) MPPMaskDataType dataType;
  • 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

    Objective-C

    @property (nonatomic, readonly) const UInt8 *_Nonnull uint8Data;
  • 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

    Objective-C

    @property (nonatomic, readonly) const float *_Nonnull float32Data;
  • Initializes an Mask object of type uInt8 with the given UInt8* data, width and height.

    If shouldCopy is set to true, the newly created Mask stores a reference to a deep copied uint8Data. Since deep copies are expensive, it is recommended to not set shouldCopy unless the Mask must outlive the passed in uint8Data.

    Declaration

    Objective-C

    - (nullable instancetype)initWithUInt8Data:(nonnull const UInt8 *)uint8Data
                                         width:(NSInteger)width
                                        height:(NSInteger)height
                                    shouldCopy:(BOOL)shouldCopy;

    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 given UInt8* data, width and height.

  • Initializes an Mask object of type float32 with the given float* data, width and height.

    If shouldCopy is set to true, the newly created Mask stores a reference to a deep copied float32Data. Since deep copies are expensive, it is recommended to not set shouldCopy unless the Mask must outlive the passed in float32Data.

    Declaration

    Objective-C

    - (nullable instancetype)initWithFloat32Data:(nonnull const float *)float32Data
                                           width:(NSInteger)width
                                          height:(NSInteger)height
                                      shouldCopy:(BOOL)shouldCopy;

    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 given float* data, width and height.

  • Unavailable.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Undocumented

    Declaration

    Objective-C

    + (instancetype)new NS_UNAVAILABLE;