Page Summary
-
MLImageis an object used for on-device machine learning, representing an image with properties like width, height, and orientation. -
It can be initialized using various sources: a standard image, a pixel buffer, or a sample buffer, each with specific requirements.
-
If initialized with an image, the
CGImageproperty of the input image must not beNULLfor successful creation of theMLImageinstance. -
MLImagestores the source type and provides access to the underlying data through properties likeimage,pixelBuffer, andsampleBuffer, which may benildepending on the source type.
MLImage
class
MLImage
:
NSObject
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
imageSourceTypeis.image, the default value isimage.imageOrientation; otherwise the default value is.up.Declaration
Swift
var orientation : Int32 { get set } -
The type of the image source.
Declaration
Swift
var imageSourceType : MLImageSourceType { get } -
The source image.
nilifimageSourceTypeis not.image.Declaration
Swift
var image : UnsafeMutablePointer < Int32 > ? { get } -
The source pixel buffer.
nilifimageSourceTypeis not.pixelBuffer.Declaration
Swift
var pixelBuffer : CVPixelBuffer ? { get } -
The source sample buffer.
nilifimageSourceTypeis not.sampleBuffer.Declaration
Swift
var sampleBuffer : CMSampleBuffer ? { get } -
Initializes an
MLImageobject with the given image.Declaration
Swift
init ?( image : Any ! )Parameters
imageThe image to use as the source. Its
CGImageproperty must not beNULL.Return Value
A new
MLImageinstance with the given image as the source.nilif the givenimageisnilor invalid. -
Initializes an
MLImageobject with the given pixel buffer.Declaration
Swift
init ?( pixelBuffer : CVPixelBuffer )Parameters
pixelBufferThe pixel buffer to use as the source. It will be retained by the new
MLImageinstance for the duration of its lifecycle.Return Value
A new
MLImageinstance with the given pixel buffer as the source.nilif the given pixel buffer isnilor invalid. -
Initializes an
MLImageobject with the given sample buffer.Declaration
Swift
init ?( sampleBuffer : CMSampleBuffer )Parameters
sampleBufferThe sample buffer to use as the source. It will be retained by the new
MLImageinstance 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 ofCMSampleBuffers.Return Value
A new
MLImageinstance with the given sample buffer as the source.nilif the given sample buffer isnilor invalid. -
Unavailable.


