detectFromCameraImage method
- Object cameraImage, {
- CameraFrameRotation? rotation,
- bool? isBgra,
- int? maxDim,
One-call wrapper for live camera streams: takes a CameraImage-shaped
object directly (any object exposing width, height, and planes with
bytes / bytesPerRow / bytesPerPixel) and runs YUV packing, colour
conversion, rotation, and downscale in the detection isolate, all off
the UI thread.
Returns an empty list (not an error) when the plane shape can't be
decoded. Throws at runtime if cameraImage doesn't expose the expected
shape.
isBgra selects BGRA vs. RGBA for the desktop single-plane path; ignored
for YUV input (Android/iOS). Defaults to true on macOS (BGRA) and
false on Windows/Linux (RGBA). Only pass this explicitly if you are
using a non-standard camera plugin that delivers a different format.
Throws StateError if initialize has not been called.
Implementation
Future<List<Hand>> detectFromCameraImage(
Object cameraImage, {
CameraFrameRotation? rotation,
bool? isBgra,
int? maxDim,
}) async {
if (!isReady) {
throw StateError(
'HandDetector not initialized. Call initialize() first.');
}
final frame = prepareCameraFrameFromImage(
cameraImage,
rotation: rotation,
isBgra: isBgra ?? Platform.isMacOS,
);
if (frame == null) return const <Hand>[];
return detectFromCameraFrame(frame, maxDim: maxDim);
}