MLKitVision Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
MLImage
An image used in on-device machine learning.
-
Width of the image in pixels.
Declaration
Swift
var
width
:
CGFloat
{
get
}
-
Height of the image in pixels.
Declaration
Swift
var
height
:
CGFloat
{
get
}
-
The display orientation of the image. If imageSourceType
is .image
, the default value is image.imageOrientation
; otherwise the default value is .up
.
Declaration
Swift
var
orientation
:
Int32
{
get
set
}
-
The type of the image source.
-
Declaration
Swift
var
image
:
UnsafeMutablePointer
<
Int32
>
?
{
get
}
-
Declaration
Swift
var
pixelBuffer
:
CVPixelBuffer
?
{
get
}
-
Declaration
Swift
var
sampleBuffer
:
CMSampleBuffer
?
{
get
}
-
Initializes an MLImage
object with the given image.
Declaration
Swift
init
?(
image
:
Any
!
)
Parameters
image
The image to use as the source. Its CGImage
property must not be NULL
.
Return Value
A new MLImage
instance with the given image as the source. nil
if the given image
is nil
or invalid.
-
Initializes an MLImage
object with the given pixel buffer.
Declaration
Swift
init
?(
pixelBuffer
:
CVPixelBuffer
)
Parameters
pixelBuffer
The pixel buffer to use as the source. It will be retained by the new MLImage
instance for the duration of its lifecycle.
Return Value
A new MLImage
instance with the given pixel buffer as the source. nil
if the given
pixel buffer is nil
or invalid.
-
Initializes an MLImage
object with the given sample buffer.
Declaration
Swift
init
?(
sampleBuffer
:
CMSampleBuffer
)
Parameters
sampleBuffer
The sample buffer to use as the source. It will be retained by the new MLImage
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 of CMSampleBuffer
s.
Return Value
A new MLImage
instance with the given sample buffer as the source. nil
if the given
sample buffer is nil
or invalid.
-
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\u003eMLImage\u003c/code\u003e is an object used for on-device machine learning, representing an image and its properties like dimensions and orientation.\u003c/p\u003e\n"],["\u003cp\u003eIt can be initialized using various sources, including a \u003ccode\u003eUIImage\u003c/code\u003e, a \u003ccode\u003eCVPixelBuffer\u003c/code\u003e, or a \u003ccode\u003eCMSampleBuffer\u003c/code\u003e from a camera's video output.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMLImage\u003c/code\u003e object provides access to the underlying image data and its characteristics for use in machine learning models.\u003c/p\u003e\n"],["\u003cp\u003eIf initialized with a \u003ccode\u003eCVPixelBuffer\u003c/code\u003e or \u003ccode\u003eCMSampleBuffer\u003c/code\u003e, \u003ccode\u003eMLImage\u003c/code\u003e retains them for its lifecycle.\u003c/p\u003e\n"]]],["MLImage, an image class for on-device machine learning, stores image data and metadata. Key properties include `width`, `height`, `orientation`, and `imageSourceType`. The class allows initialization with an `image`, `pixelBuffer`, or `sampleBuffer`, each with specific source requirements. Accessors `image`, `pixelBuffer`, or `sampleBuffer` provide the source if `imageSourceType` matches. Initialization returns `nil` for invalid sources. `init()` method is unavailable.\n"],null,["# MLKitVision Framework Reference\n\nMLImage\n=======\n\n class MLImage : NSObject\n\nAn image used in on-device machine learning.\n- `\n ``\n ``\n `\n\n ### [width](#/c:objc(cs)GMLImage(py)width)\n\n `\n ` \n Width of the image in pixels. \n\n #### Declaration\n\n Swift \n\n var width: CGFloat { get }\n\n- `\n ``\n ``\n `\n\n ### [height](#/c:objc(cs)GMLImage(py)height)\n\n `\n ` \n Height of the image in pixels. \n\n #### Declaration\n\n Swift \n\n var height: CGFloat { get }\n\n- `\n ``\n ``\n `\n\n ### [orientation](#/c:objc(cs)GMLImage(py)orientation)\n\n `\n ` \n The display orientation of the image. If [imageSourceType](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)imageSourceType) is [.image](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)image), the default value is\n `image.imageOrientation`; otherwise the default value is `.up`. \n\n #### Declaration\n\n Swift \n\n var orientation: Int32 { get set }\n\n- `\n ``\n ``\n `\n\n ### [imageSourceType](#/c:objc(cs)GMLImage(py)imageSourceType)\n\n `\n ` \n The type of the image source. \n\n #### Declaration\n\n Swift \n\n var imageSourceType: ../Type-Definitions.html#/c:GMLImage.h@T@GMLImageSourceType { get }\n\n- `\n ``\n ``\n `\n\n ### [image](#/c:objc(cs)GMLImage(py)image)\n\n `\n ` \n The source image. `nil` if [imageSourceType](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)imageSourceType) is not `.image`. \n\n #### Declaration\n\n Swift \n\n var image: UnsafeMutablePointer\u003cInt32\u003e? { get }\n\n- `\n ``\n ``\n `\n\n ### [pixelBuffer](#/c:objc(cs)GMLImage(py)pixelBuffer)\n\n `\n ` \n The source pixel buffer. `nil` if [imageSourceType](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)imageSourceType) is not `.pixelBuffer`. \n\n #### Declaration\n\n Swift \n\n var pixelBuffer: CVPixelBuffer? { get }\n\n- `\n ``\n ``\n `\n\n ### [sampleBuffer](#/c:objc(cs)GMLImage(py)sampleBuffer)\n\n `\n ` \n The source sample buffer. `nil` if [imageSourceType](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)imageSourceType) is not `.sampleBuffer`. \n\n #### Declaration\n\n Swift \n\n var sampleBuffer: CMSampleBuffer? { get }\n\n- `\n ``\n ``\n `\n\n ### [init(image:)](#/c:objc(cs)GMLImage(im)initWithImage:)\n\n `\n ` \n Initializes an `MLImage` object with the given image. \n\n #### Declaration\n\n Swift \n\n init?(image: Any!)\n\n #### Parameters\n\n |---------------|----------------------------------------------------------------------------|\n | ` `*image*` ` | The image to use as the source. Its `CGImage` property must not be `NULL`. |\n\n #### Return Value\n\n A new `MLImage` instance with the given image as the source. `nil` if the given [image](../Classes/MLImage.html#/c:objc(cs)GMLImage(py)image)\n is `nil` or invalid.\n- `\n ``\n ``\n `\n\n ### [init(pixelBuffer:)](#/c:objc(cs)GMLImage(im)initWithPixelBuffer:)\n\n `\n ` \n Initializes an `MLImage` object with the given pixel buffer. \n\n #### Declaration\n\n Swift \n\n init?(pixelBuffer: CVPixelBuffer)\n\n #### Parameters\n\n |---------------------|-----------------------------------------------------------------------------------------------------------------------------|\n | ` `*pixelBuffer*` ` | The pixel buffer to use as the source. It will be retained by the new `MLImage` instance for the duration of its lifecycle. |\n\n #### Return Value\n\n A new `MLImage` instance with the given pixel buffer as the source. `nil` if the given\n pixel buffer is `nil` or invalid.\n- `\n ``\n ``\n `\n\n ### [init(sampleBuffer:)](#/c:objc(cs)GMLImage(im)initWithSampleBuffer:)\n\n `\n ` \n Initializes an `MLImage` object with the given sample buffer. \n\n #### Declaration\n\n Swift \n\n init?(sampleBuffer: CMSampleBuffer)\n\n #### Parameters\n\n |----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*sampleBuffer*` ` | The sample buffer to use as the source. It will be retained by the new `MLImage` 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 of `CMSampleBuffer`s. |\n\n #### Return Value\n\n A new `MLImage` instance with the given sample buffer as the source. `nil` if the given\n sample buffer is `nil` or invalid.\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)GMLImage(im)init)\n\n `\n ` \n Unavailable."]]