Class VisionImage
java.lang.Object
com.codename1.ai.vision.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.-
Method Summary
Modifier and TypeMethodDescriptionstatic VisionImageencoded(byte[] bytes) Creates an encoded JPEG or PNG input whose stored pixels are already upright.static VisionImageencoded(byte[] bytes, int rotationDegrees) Creates an encoded JPEG or PNG input with display orientation metadata.static VisionImagefromCameraFrame(CameraFrame frame) Copies the buffer selected by the camera frame's format, together with its timestamp and orientation.byte[]intbyte[]intlongintgetWidth()static VisionImagepixels(byte[] bytes, int width, int height, FrameFormat format, int rotationDegrees) Creates raw NV21 or RGBA8888 input with display orientation metadata.
-
Method Details
-
encoded
Creates an encoded JPEG or PNG input whose stored pixels are already upright. This method does not inspect EXIF orientation metadata. Useencoded(byte[], int)when the encoded image needs a clockwise display rotation before analysis.- Parameters:
bytes- complete encoded image, copied by this method- Returns:
- immutable image input
- Throws:
IllegalArgumentException- ifbytesisnullor empty
-
encoded
Creates an encoded JPEG or PNG input with display orientation metadata. The rotation describes how the stored pixels must be rotated clockwise to appear upright; for example, pass90for 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 outsidefromCameraFrame(CameraFrame)must supply the EXIF-derived rotation when it is relevant.- Parameters:
bytes- complete encoded image, copied by this methodrotationDegrees- clockwise display rotation; only 0, 90, 180, or 270 degrees are supported- Returns:
- immutable image input
- Throws:
IllegalArgumentException- ifbytesisnullor 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) Creates raw NV21 or RGBA8888 input with display orientation metadata.- Parameters:
bytes- pixel buffer informat, copied by this methodwidth- unrotated pixel widthheight- unrotated pixel heightformat- supported raw frame formatrotationDegrees- clockwise display rotation; only 0, 90, 180, or 270 degrees are supported- Returns:
- immutable image input
- Throws:
IllegalArgumentException- if the data or dimensions are empty, ifformatis notFrameFormat.NV21orFrameFormat.RGBA8888, or if the rotation is not a quarter turn
-
fromCameraFrame
Copies the buffer selected by the camera frame's format, together with its timestamp and orientation. JPEG frames copy onlyCameraFrame.getJpegBytes(); NV21 and RGBA8888 frames copy onlyCameraFrame.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:
frame- callback-owned frame- Returns:
- detached immutable input safe for asynchronous analysis
- Throws:
IllegalArgumentException- if the frame reports a rotation other than 0, 90, 180, or 270 degrees
-
getEncodedBytes
public byte[] getEncodedBytes()- Returns:
- a defensive copy of encoded bytes, or
nullfor raw input
-
getPixels
public byte[] getPixels()- Returns:
- a defensive copy of raw pixels, or
nullfor encoded input
-
getWidth
public int getWidth()- Returns:
- raw pixel width, or zero for encoded input
-
getHeight
public int getHeight()- Returns:
- raw pixel height, or zero for encoded input
-
getRotationDegrees
public int getRotationDegrees()- Returns:
- normalized clockwise rotation: 0, 90, 180, or 270
-
getTimestampNanos
public long getTimestampNanos()- Returns:
- capture timestamp in nanoseconds, or zero for manual input
-
getFormat
- Returns:
- encoded/raw frame format
-