The Mobile Vision API is now a part of ML Kit. We strongly encourage you to try it out, as it comes with new capabilities like on-device image labeling! Also, note that we ultimately plan to wind down the Mobile Vision API, with all new on-device ML capabilities released via ML Kit. Feel free to reach out to Firebase support for help.

GMVUtility Class

GMVUtility Class Reference

Inherits NSObject.

Class Method Summary

(UIImage *) + sampleBufferTo32RGBA:
 Converts CMSampleBuffer to UIImage. More...
 
(NSData *) + anySampleBufferFormatTo32RGBA:
 Converts CMSampleBuffer to RGBA8888 data format. More...
 
(GMVImageOrientation+ imageOrientationFromOrientation:withCaptureDevicePosition:defaultDeviceOrientation:
 This function determines the image exif metadata using device orientation and device position. More...
 
(UIImage *) + imageFromData:width:height:
 Converts a RGBA buffer to an UIImage. More...
 

Method Detail

+ (UIImage *) sampleBufferTo32RGBA: (CMSampleBufferRef)  sampleBuffer

Converts CMSampleBuffer to UIImage.

This function supports 420v, 420f, and BGRA CVPixelBufferPixelFormatTypes.

Parameters
sampleBufferThe buffer to convert to UIImage.
Returns
UIImage in RGBA8888 format.
+ (NSData *) anySampleBufferFormatTo32RGBA: (CMSampleBufferRef)  sampleBuffer

Converts CMSampleBuffer to RGBA8888 data format.

This function supports 420v, 420f, and BGRA CVPixelBufferPixelFormatTypes. The output data corresponds to an image with exact same width and height than input sampleBuffer. The number of bytes in a pixel row corresponds to the returned NSData's length divided by height.

Parameters
sampleBufferThe buffer to convert to NSData.
Returns
NSData in RGBA8888 format.
+ (GMVImageOrientation) imageOrientationFromOrientation: (UIDeviceOrientation)  deviceOrientation
withCaptureDevicePosition: (AVCaptureDevicePosition)  position
defaultDeviceOrientation: (UIDeviceOrientation)  defaultOrientation 

This function determines the image exif metadata using device orientation and device position.

The orientation is significant when using detections on an image generated from AVCaptureVideoDataOutput CMSampleBuffer. AVCaptureVideoDataOutput does not support setting the video orientation, therefore the client has to handle the rotation on their own. GMVImageOrientation can be passed in to GMVDetector featuresInImage:options: to let the detector handle the video rotation for you.

Parameters
deviceOrientationThe device orientation.
positionThe caputre device position.
defaultOrientationThe default device orientation to use when deviceOrientaiton has value as UIDeviceOrientationFaceUp or UIDeviceOrientationFaceDown.
Returns
GMVImageOrientation value to express an image exif metadata.
+ (UIImage *) imageFromData: (NSData *)  data
width: (size_t)  width
height: (size_t)  height 

Converts a RGBA buffer to an UIImage.

The number of bytes in a pixel row is inferred from data's length divided by height.

Parameters
dataThe RGBA buffer.
widthThe width of the buffer.
heightThe height of the height of the buffer.
Returns
An UIImage instance constructed from data.