public final class VisionImage
- Object
- VisionImage
Immutable input for encoded still images or raw camera pixels. Factory
methods defensively copy their arrays. In particular,
fromCameraFrame(CameraFrame) detaches from callback-owned buffers
that a camera backend may recycle when the callback returns.
Pick the factory that matches where the image came from:
// A file: the gallery, or CapturedPhoto.getFilePath()
VisionImage.fromFile(photo.getFilePath());
// An image already in memory
VisionImage.fromImage(label.getIcon());
// Bytes you decoded or downloaded yourself
VisionImage.encoded(jpegBytes);
// A live camera frame, which also carries the frame's rotation
VisionImage.fromCameraFrame(frame);
Only encoded(byte[], int) needs a rotation argument, and only when
the stored pixels are not already upright – this class does not read EXIF.
Methods
Inherited methods
Method details
encoded
public static VisionImage encoded(byte[] bytes)encoded(byte[], int) when the encoded image needs a clockwise
display rotation before analysis.Parameters
bytesbyte[]- complete encoded image, copied by this method
Returns
Throws
IllegalArgumentException- if
bytesisnullor empty
encoded
public static VisionImage encoded(byte[] bytes, int rotationDegrees)90 for a portrait JPEG
whose pixels are stored in landscape orientation. Decoders on Android
and Apple platforms receive this value directly, so detected bounds and
points use the displayed orientation. This method does not parse EXIF;
callers loading an image outside fromCameraFrame(CameraFrame)
must supply the EXIF-derived rotation when it is relevant.Parameters
bytesbyte[]- complete encoded image, copied by this method
rotationDegreesint- clockwise display rotation; only 0, 90, 180, or 270 degrees are supported
Returns
Throws
IllegalArgumentException- if
bytesisnullor empty, or if the rotation is not a quarter turn
pixels
public static VisionImage pixels(byte[] bytes, int width, int height, FrameFormat format, int rotationDegrees)Parameters
bytesbyte[]- pixel buffer in
format, copied by this method widthint- unrotated pixel width
heightint- unrotated pixel height
formatFrameFormat- supported raw frame format
rotationDegreesint- clockwise display rotation; only 0, 90, 180, or 270 degrees are supported
Returns
Throws
IllegalArgumentException- if the data or dimensions are empty,
if
formatis notFrameFormat.NV21orFrameFormat.RGBA8888, or if the rotation is not a quarter turn
fromCameraFrame
public static VisionImage fromCameraFrame(CameraFrame frame)CameraFrame.getJpegBytes(); NV21 and RGBA8888 frames copy only
CameraFrame.getRawBytes() when the port supplies that buffer.
If a port cannot supply the requested raw format, this method copies
the always-available JPEG fallback instead. This preserves the raw
pipeline without creating an empty image on JPEG-only camera ports.Parameters
frameCameraFrame- callback-owned frame
Returns
Throws
IllegalArgumentException- if the frame reports a rotation other than 0, 90, 180, or 270 degrees
fromFile
public static VisionImage fromFile(String path)
throws IOExceptionReads a JPEG or PNG file from FileSystemStorage and wraps it
for analysis. This is the usual bridge from the image picker or from
CapturedPhoto.getFilePath() to an
analyzer.
Like encoded(byte[]) this assumes the stored pixels are
already upright and does not parse EXIF. Use
encoded(byte[], int) when a rotation has to be applied.
Parameters
pathString- a FileSystemStorage path
Returns
Throws
IOException- if the file cannot be read
IllegalArgumentException- if the file is empty
fromImage
public static VisionImage fromImage(Image image)Wraps an in-memory Codename One image for analysis.
An EncodedImage passes its original JPEG or PNG bytes straight
through, which is both cheaper and higher fidelity than re-encoding.
Any other image is read as RGBA pixels. Either way the caller’s image
is left untouched.
Parameters
imageImage- the image to analyze
Returns
Throws
NullPointerException- if
imageisnull IllegalArgumentException- if the image has no pixels
getEncodedBytes
public byte[] getEncodedBytes()Returns
null for raw inputgetPixels
public byte[] getPixels()Returns
null for encoded inputgetWidth
public int getWidth()Returns
getHeight
public int getHeight()Returns
getRotationDegrees
public int getRotationDegrees()Returns
getTimestampNanos
public long getTimestampNanos()Returns
getFormat
public FrameFormat getFormat()