detectFromCameraImage method

Future<List<Hand>> detectFromCameraImage(
  1. Object cameraImage, {
  2. CameraFrameRotation? rotation,
  3. bool? isBgra,
  4. 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). When omitted, the byte order is read from the frame's format.raw: 'BGRA' (camera_desktop 2.x on every desktop platform) selects BGRA and 'RGBA' (camera_desktop 1.x on Linux and Windows) selects RGBA. Any other value falls back to BGRA on macOS and RGBA elsewhere. 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,
  );
  if (frame == null) return const <Hand>[];
  return detectFromCameraFrame(frame, maxDim: maxDim);
}