TensorImageUtils¶
-
public final class
TensorImageUtils¶ Contains utility functions for
org.pytorch.Tensorcreation fromandroid.graphics.Bitmaporandroid.media.Imagesource.
Fields¶
Methods¶
bitmapToFloat32Tensor¶
-
public static Tensor
bitmapToFloat32Tensor(Bitmap bitmap, float[] normMeanRGB, float[] normStdRGB)¶ Creates new
org.pytorch.Tensorfrom fullandroid.graphics.Bitmap, normalized with specified in parameters mean and std.- Parameters
normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order
normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order
bitmapToFloat32Tensor¶
-
public static Tensor
bitmapToFloat32Tensor(Bitmap bitmap, int x, int y, int width, int height, float[] normMeanRGB, float[] normStdRGB)¶ Creates new
org.pytorch.Tensorfrom specified area ofandroid.graphics.Bitmap, normalized with specified in parameters mean and std.- Parameters
bitmap –
android.graphics.Bitmapas a source for Tensor datax –
x coordinate of top left corner of bitmap’s area
y –
y coordinate of top left corner of bitmap’s area
width –
width of bitmap’s area
height –
height of bitmap’s area
normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order
normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order
bitmapToFloatBuffer¶
-
public static void
bitmapToFloatBuffer(Bitmap bitmap, int x, int y, int width, int height, float[] normMeanRGB, float[] normStdRGB, FloatBuffer outBuffer, int outBufferOffset)¶ Writes tensor content from specified
android.graphics.Bitmap, normalized with specified in parameters mean and std to specifiedjava.nio.FloatBufferwith specified offset.- Parameters
bitmap –
android.graphics.Bitmapas a source for Tensor datax –
x coordinate of top left corner of bitmap’s area
y –
y coordinate of top left corner of bitmap’s area
width –
width of bitmap’s area
height –
height of bitmap’s area
normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order
normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order
imageYUV420CenterCropToFloat32Tensor¶
-
public static Tensor
imageYUV420CenterCropToFloat32Tensor(Image image, int rotateCWDegrees, int tensorWidth, int tensorHeight, float[] normMeanRGB, float[] normStdRGB)¶ Creates new
org.pytorch.Tensorfrom specified area ofandroid.media.Image, doing optional rotation, scaling (nearest) and center cropping.- Parameters
image –
android.media.Imageas a source for Tensor datarotateCWDegrees – Clockwise angle through which the input image needs to be rotated to be upright. Range of valid values: 0, 90, 180, 270
tensorWidth – return tensor width, must be positive
tensorHeight – return tensor height, must be positive
normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order
normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order
imageYUV420CenterCropToFloatBuffer¶
-
public static void
imageYUV420CenterCropToFloatBuffer(Image image, int rotateCWDegrees, int tensorWidth, int tensorHeight, float[] normMeanRGB, float[] normStdRGB, FloatBuffer outBuffer, int outBufferOffset)¶ Writes tensor content from specified
android.media.Image, doing optional rotation, scaling (nearest) and center cropping to specifiedjava.nio.FloatBufferwith specified offset.- Parameters
image –
android.media.Imageas a source for Tensor datarotateCWDegrees – Clockwise angle through which the input image needs to be rotated to be upright. Range of valid values: 0, 90, 180, 270
tensorWidth – return tensor width, must be positive
tensorHeight – return tensor height, must be positive
normMeanRGB – means for RGB channels normalization, length must equal 3, RGB order
normStdRGB – standard deviation for RGB channels normalization, length must equal 3, RGB order
outBuffer – Output buffer, where tensor content will be written
outBufferOffset – Output buffer offset with which tensor content will be written