GMVUtility.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #import <AVFoundation/AVFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #import <UIKit/UIKit.h>
  4. #import "GMVDetectorConstants.h"
  5. @interface GMVUtility : NSObject
  6. /**
  7. * Converts CMSampleBuffer to UIImage. This function supports 420v, 420f, and BGRA
  8. * CVPixelBufferPixelFormatTypes.
  9. *
  10. * @param sampleBuffer The buffer to convert to UIImage.
  11. * @returns UIImage in RGBA8888 format.
  12. */
  13. + (UIImage *)sampleBufferTo32RGBA:(CMSampleBufferRef)sampleBuffer;
  14. /**
  15. * Converts CMSampleBuffer to RGBA8888 data format. This function supports 420v, 420f, and BGRA
  16. * CVPixelBufferPixelFormatTypes. The output data corresponds to an image with exact same width
  17. * and height than input |sampleBuffer|. The number of bytes in a pixel row corresponds to the
  18. * returned NSData's length divided by height.
  19. *
  20. * @param sampleBuffer The buffer to convert to NSData.
  21. * @returns NSData in RGBA8888 format.
  22. */
  23. + (NSData *)anySampleBufferFormatTo32RGBA:(CMSampleBufferRef)sampleBuffer;
  24. /**
  25. * This function determines the image exif metadata using device orientation and device
  26. * position. The orientation is significant when using detections on an image generated
  27. * from AVCaptureVideoDataOutput CMSampleBuffer. AVCaptureVideoDataOutput does not support
  28. * setting the video orientation, therefore the client has to handle the rotation on their own.
  29. * GMVImageOrientation can be passed in to GMVDetector featuresInImage:options: to let the
  30. * detector handle the video rotation for you.
  31. *
  32. * @param deviceOrientation The device orientation.
  33. * @param position The caputre device position.
  34. * @param defaultOrientation The default device orientation to use when |deviceOrientaiton| has
  35. * value as UIDeviceOrientationFaceUp or UIDeviceOrientationFaceDown.
  36. * @returns GMVImageOrientation value to express an image exif metadata.
  37. */
  38. + (GMVImageOrientation)imageOrientationFromOrientation:(UIDeviceOrientation)deviceOrientation
  39. withCaptureDevicePosition:(AVCaptureDevicePosition)position
  40. defaultDeviceOrientation:(UIDeviceOrientation)defaultOrientation;
  41. /**
  42. * Converts a RGBA buffer to an UIImage. The number of bytes in a pixel row is inferred from
  43. * |data|'s length divided by |height|.
  44. *
  45. * @param data The RGBA buffer.
  46. * @param width The width of the buffer.
  47. * @param height The height of the height of the buffer.
  48. * @returns An UIImage instance constructed from |data|.
  49. */
  50. + (UIImage *)imageFromData:(NSData *)data width:(size_t)width height:(size_t)height;
  51. @end