MLKitVision Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
MLKVisionImage
An image or image buffer used for vision detection.
-
The display orientation of the image. The default is .up
.
Declaration
Objective-C
@property
(
nonatomic
)
int
orientation
;
-
Initializes a VisionImage
object with the given image.
Declaration
Objective-C
-
(
nonnull
instancetype
)
initWithImage
:(
id
)
image
;
Parameters
image
Image to use in vision detection. The given image should be rotated, so its imageOrientation
property is set to .up
. The UIImage
must have non-NULL CGImage
property.
Return Value
A VisionImage
instance with the given image.
-
Initializes a VisionImage
object with the given image buffer. To improve performance, it is
recommended to minimize the lifespan and number of instances of this class when initializing with
a CMSampleBufferRef
.
Declaration
Objective-C
-
(
nonnull
instancetype
)
initWithBuffer
:(
nonnull
CMSampleBufferRef
)
sampleBuffer
;
Parameters
sampleBuffer
Image buffer to use in vision detection. The buffer must be based on
a pixel buffer (not compressed data), and the pixel format must be one of:
- kCVPixelFormatType_32BGRA
- kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
- kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
In practice: this works with the video output of the phone’s camera, but not other
arbitrary sources of CMSampleBufferRef
s.
Return Value
A VisionImage
instance with the given image buffer.
-
Declaration
Objective-C
-
(
nonnull
instancetype
)
init
;
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eMLKVisionImage\u003c/code\u003e is an object used for vision detection tasks, accepting either images or image buffers as input.\u003c/p\u003e\n"],["\u003cp\u003eIt's crucial to set the \u003ccode\u003eimageOrientation\u003c/code\u003e property of input \u003ccode\u003eUIImage\u003c/code\u003e to \u003ccode\u003e.up\u003c/code\u003e and ensure it has a non-NULL \u003ccode\u003eCGImage\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003eCMSampleBufferRef\u003c/code\u003e, the buffer must contain uncompressed pixel data in specific supported formats.\u003c/p\u003e\n"],["\u003cp\u003eFor performance, minimize the creation and lifespan of \u003ccode\u003eMLKVisionImage\u003c/code\u003e instances, especially when initialized with \u003ccode\u003eCMSampleBufferRef\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eMLKVisionImage\u003c/code\u003e offers a property \u003ccode\u003eorientation\u003c/code\u003e to specify the display orientation of the image, defaulting to \u003ccode\u003e.up\u003c/code\u003e.\u003c/p\u003e\n"]]],["`MLKVisionImage` is used for vision detection, handling images or image buffers. Key actions include initializing an object with `initWithImage:`, accepting an image where the `imageOrientation` property is set to `.up`, or initializing with `initWithBuffer:`, accepting a `CMSampleBufferRef`. The `orientation` property defines the display orientation, defaulting to `.up`. Initialization using `init` alone is unavailable. For buffer initialization, specific pixel formats are required for proper function, such as `kCVPixelFormatType_32BGRA`.\n"],null,["# MLKitVision Framework Reference\n\nMLKVisionImage\n==============\n\n\n @interface MLKVisionImage : NSObject \u003c../Protocols.html#/c:objc(pl)MLKCompatibleImage\u003e\n\nAn image or image buffer used for vision detection.\n- `\n ``\n ``\n `\n\n ### [orientation](#/c:objc(cs)MLKVisionImage(py)orientation)\n\n `\n ` \n The display orientation of the image. The default is `.up`. \n\n #### Declaration\n\n Objective-C \n\n @property (nonatomic) int orientation;\n\n- `\n ``\n ``\n `\n\n ### [-initWithImage:](#/c:objc(cs)MLKVisionImage(im)initWithImage:)\n\n `\n ` \n Initializes a `VisionImage` object with the given image. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull instancetype)initWithImage:(id)image;\n\n #### Parameters\n\n |---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*image*` ` | Image to use in vision detection. The given image should be rotated, so its `imageOrientation` property is set to `.up`. The `UIImage` must have non-NULL `CGImage` property. |\n\n #### Return Value\n\n A `VisionImage` instance with the given image.\n- `\n ``\n ``\n `\n\n ### [-initWithBuffer:](#/c:objc(cs)MLKVisionImage(im)initWithBuffer:)\n\n `\n ` \n Initializes a `VisionImage` object with the given image buffer. To improve performance, it is\n recommended to minimize the lifespan and number of instances of this class when initializing with\n a `CMSampleBufferRef`. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull instancetype)initWithBuffer:(nonnull CMSampleBufferRef)sampleBuffer;\n\n #### Parameters\n\n |----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*sampleBuffer*` ` | Image buffer to use in vision detection. The buffer must be based on a pixel buffer (not compressed data), and the pixel format must be one of: - `kCVPixelFormatType_32BGRA` - `kCVPixelFormatType_420YpCbCr8BiPlanarFullRange` - `kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange` In practice: this works with the video output of the phone's camera, but not other arbitrary sources of `CMSampleBufferRef`s. |\n\n #### Return Value\n\n A `VisionImage` instance with the given image buffer.\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)MLKVisionImage(im)init)\n\n `\n ` \n Unavailable. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull instancetype)init;"]]