MPPImage
@interface MPPImage : NSObject
An image used in on-device machine learning using MediaPipe Task library.
-
Width of the image in pixels.
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat width;
-
Height of the image in pixels.
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat height;
-
The display orientation of the image. If
imageSourceType
is.image
, the default value isimage.imageOrientation
; otherwise the default value isUIImage.Orientation.up
. If theMPImage
is being used as input for any MediaPipe vision tasks and is set to any orientation other thanUIImage.Orientation.up
, inference will be performed on a rotated copy of the image according to the orientation.Declaration
Objective-C
@property (nonatomic, readonly) UIImageOrientation orientation;
-
The type of the image source.
Declaration
Objective-C
@property (nonatomic, readonly) MPPImageSourceType imageSourceType;
-
The source image.
nil
ifimageSourceType
is not.image
.Declaration
Objective-C
@property (nonatomic, readonly, nullable) UIImage *image;
-
The source pixel buffer.
nil
ifimageSourceType
is not.pixelBuffer
.Declaration
Objective-C
@property (nonatomic, readonly, nullable) CVPixelBufferRef pixelBuffer;
-
The source sample buffer.
nil
ifimageSourceType
is not.sampleBuffer
.Declaration
Objective-C
@property (nonatomic, readonly, nullable) CMSampleBufferRef sampleBuffer;
-
Initializes an
MPImage
object with the givenUIImage
.The orientation of the newly created
MPImage
will be equal to theimageOrientation
ofUIImage
and when sent to the vision tasks for inference, rotation will be applied accordingly. To create anMPImage
with an orientation different from itsimageOrientation
, please useMPImage(uiImage:orientation:)s
.Declaration
Objective-C
- (nullable instancetype)initWithUIImage:(nonnull UIImage *)image error:(NSError *_Nullable *_Nullable)error;
Parameters
image
The image to use as the source. Its
CGImage
property must not beNULL
.error
An optional error parameter populated when there is an error in initializing the
MPImage
.Return Value
A new
MPImage
instance with the given image as the source.nil
if the givenimage
isnil
or invalid. -
Initializes an
MPImage
object with the givenUIImage
and orientation.The given orientation will be used to calculate the rotation to be applied to the
UIImage
before inference is performed on it by the vision tasks. TheimageOrientation
stored in theUIImage
is ignored whenMPImage
objects created by this method are sent to the vision tasks for inference. UseMPImage(uiImage:)
to initialize images with theimageOrientation
ofUIImage
.If the newly created
MPImage
is used as input for any MediaPipe vision tasks, inference will be performed on a copy of the image rotated according to the orientation.Declaration
Objective-C
- (nullable instancetype)initWithUIImage:(nonnull UIImage *)image orientation:(UIImageOrientation)orientation error:(NSError *_Nullable *_Nullable)error;
Parameters
image
The image to use as the source. Its
CGImage
property must not beNULL
.orientation
The display orientation of the image. This will be stored in the property
orientation
MPImage
and will override theimageOrientation
of the passed inUIImage
.error
An optional error parameter populated when there is an error in initializing the
MPImage
.Return Value
A new
MPImage
instance with the given image as the source.nil
if the givenimage
isnil
or invalid. -
Initializes an
MPImage
object with the given pixel buffer.The orientation of the newly created
MPImage
will beUIImageOrientationUp
. Hence, if this image is used as input for any MediaPipe vision tasks, inference will be performed on the it without any rotation. To create anMPImage
with a different orientation, please useMPImage(pixelBuffer:orientation:)
.Declaration
Objective-C
- (nullable instancetype) initWithPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer error:(NSError *_Nullable *_Nullable)error;
Parameters
pixelBuffer
The pixel buffer to use as the source. It will be retained by the new
MPImage
instance for the duration of its lifecycle.error
An optional error parameter populated when there is an error in initializing the
MPImage
.Return Value
A new
MPImage
instance with the given pixel buffer as the source.nil
if the given pixel buffer isnil
or invalid. -
Initializes an
MPImage
object with the given pixel buffer and orientation.If the newly created
MPImage
is used as input for any MediaPipe vision tasks, inference will be performed on a copy of the image rotated according to the orientation.Declaration
Objective-C
- (nullable instancetype) initWithPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer orientation:(UIImageOrientation)orientation error:(NSError *_Nullable *_Nullable)error;
Parameters
pixelBuffer
The pixel buffer to use as the source. It will be retained by the new
MPImage
instance for the duration of its lifecycle.orientation
The display orientation of the image.
error
An optional error parameter populated when there is an error in initializing the
MPImage
.Return Value
A new
MPImage
instance with the given orientation and pixel buffer as the source.nil
if the given pixel buffer isnil
or invalid. -
Initializes an
MPImage
object with the given sample buffer.The orientation of the newly created
MPImage
will beUIImageOrientationUp
. Hence, if this image is used as input for any MediaPipe vision tasks, inference will be performed on the it without any rotation. To create anMPImage
with a different orientation, please useMPImage(sampleBuffer:orientation:)
.Declaration
Objective-C
- (nullable instancetype) initWithSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer error:(NSError *_Nullable *_Nullable)error;
Parameters
sampleBuffer
The sample buffer to use as the source. It will be retained by the new
MPImage
instance for the duration of its lifecycle. The sample buffer must be based on a pixel buffer (not compressed data). In practice, it should be the video output of the camera on an iOS device, not other arbitrary types ofCMSampleBuffer
s.Return Value
A new
MPImage
instance with the given sample buffer as the source.nil
if the given sample buffer isnil
or invalid. -
Initializes an
MPImage
object with the given sample buffer and orientation.If the newly created
MPImage
is used as input for any MediaPipe vision tasks, inference will be performed on a copy of the image rotated according to the orientation.Declaration
Objective-C
- (nullable instancetype) initWithSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer orientation:(UIImageOrientation)orientation error:(NSError *_Nullable *_Nullable)error;
Parameters
sampleBuffer
The sample buffer to use as the source. It will be retained by the new
MPImage
instance for the duration of its lifecycle. The sample buffer must be based on a pixel buffer (not compressed data). In practice, it should be the video output of the camera on an iOS device, not other arbitrary types ofCMSampleBuffer
s.orientation
The display orientation of the image.
Return Value
A new
MPImage
instance with the given orientation and sample buffer as the source.nil
if the given sample buffer isnil
or invalid. -
Unavailable.
Declaration
Objective-C
- (nonnull instancetype)init;
-
Undocumented
Declaration
Objective-C
+ (instancetype)new NS_UNAVAILABLE;