Represents an image object.
Nested Class Summary
@interface | InputImage.ImageFormat | Accepted image format of vision APIs. |
Constant Summary
int | IMAGE_FORMAT_NV21 | See
ImageFormat.NV21 . |
int | IMAGE_FORMAT_YUV_420_888 | See
ImageFormat.YUV_420_888 . |
int | IMAGE_FORMAT_YV12 | See
ImageFormat.YV12 . |
Public Method Summary
static InputImage | |
static InputImage |
fromByteArray(byte[] byteArray, int width, int height, int
rotationDegrees, int format)
Creates an
InputImage
from a byte array, e.g., what you get from
Camera callback.
|
static InputImage |
fromByteBuffer(ByteBuffer
byteBuffer, int width, int height, int rotationDegrees, int format)
Creates an
InputImage
from a ByteBuffer .
|
static InputImage | |
static InputImage |
fromMediaImage(Image
image, int rotationDegrees)
Creates an
InputImage
from an Image
object, e.g., what you obtained from
android.hardware.camera2 API.
|
Inherited Method Summary
Constants
public static final int IMAGE_FORMAT_NV21
See
ImageFormat.NV21
.
public static final int IMAGE_FORMAT_YUV_420_888
public static final int IMAGE_FORMAT_YV12
See
ImageFormat.YV12
.
Public Methods
public static InputImage fromBitmap (Bitmap bitmap, int rotationDegrees)
Creates an InputImage
from a Bitmap
.
Parameters
bitmap | the input Bitmap . |
---|---|
rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
public static InputImage fromByteArray (byte[] byteArray, int width, int height, int rotationDegrees, int format)
Creates an InputImage
from a byte array, e.g., what you get from Camera
callback.
Parameters
byteArray | the content of the image |
---|---|
width | the width of the image |
height | the height of the image |
rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
format | the image format. The supported formats are
IMAGE_FORMAT_NV21 and
IMAGE_FORMAT_YV12 . For IMAGE_FORMAT_YUV_420_888, please use
fromMediaImage(Image, int) . |
public static InputImage fromByteBuffer (ByteBuffer byteBuffer, int width, int height, int rotationDegrees, int format)
Creates an InputImage
from a ByteBuffer
.
We assume the entire buffer from position zero to its limit is all image data.
Parameters
byteBuffer | the content of the image |
---|---|
width | the width of the image |
height | the height of the image |
rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
format | the image format. The supported formats are
IMAGE_FORMAT_NV21 and
IMAGE_FORMAT_YV12 . For IMAGE_FORMAT_YUV_420_888, please use
fromMediaImage(Image, int) . |
public static InputImage fromFilePath (Context context, Uri imageUri)
Creates an InputImage
from a local image file Uri.
Throws
IOException | if the image could not be retrieved from the specified imageUri. This could happen even if the Uri came from content chooser, e.g., some users might have content providers for remote resources. |
---|
public static InputImage fromMediaImage (Image image, int rotationDegrees)
Creates an InputImage
from an Image
object, e.g., what you obtained from android.hardware.camera2
API.
Please wait for the detector to finish processing this InputImage
before you close the underlying Image
.
Parameters
image | the android.media.Image, where only JPEG / YUV_420_888 formats are supported at this moment and YUV_420_888 is more efficient for all our APIs. |
---|---|
rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |