detectBGRA8888 method

DetectResults detectBGRA8888({
  1. required Uint8List pixels,
  2. required int height,
  3. @Deprecated("width is automatically calculated from the length of the pixels.") int width = 0,
  4. required KannaRotateDeviceOrientationType deviceOrientationType,
  5. required int sensorOrientation,
  6. void onDecodeImage(
    1. Image image
    )?,
})

Detect with YOLOX Run it after initYolox

When detecting from an image byte array, specify pixels. height is the height of the image. The width of the image is calculated from pixels length.

deviceOrientationType is the device orientation. It can be obtained from CameraController of the camera package. https://github.com/flutter/plugins/blob/main/packages/camera/camera/lib/src/camera_controller.dart#L134

sensorOrientation is the orientation of the camera sensor. It can be obtained from CameraController of the camera package. https://github.com/flutter/plugins/blob/main/packages/camera/camera_platform_interface/lib/src/types/camera_description.dart#L42

onDecodeImage is a callback function to decode the image. The process of converting to a ui.Image object is heavy and affects performance. If ui.Image is not needed, it is recommended to set null.

Implementation

DetectResults detectBGRA8888({
  required Uint8List pixels,
  required int height,
  @Deprecated("width is automatically calculated from the length of the pixels.")
      int width = 0,
  required KannaRotateDeviceOrientationType deviceOrientationType,
  required int sensorOrientation,
  void Function(ui.Image image)? onDecodeImage,
}) {
  final width = pixels.length ~/ height ~/ 4;

  final rotated = kannaRotate(
    pixels: pixels,
    pixelChannel: PixelChannel.c4,
    width: width,
    height: height,
    deviceOrientationType: deviceOrientationType,
    sensorOrientation: sensorOrientation,
  );

  if (onDecodeImage != null) {
    ui.decodeImageFromPixels(
      pixels,
      width,
      height,
      ui.PixelFormat.bgra8888,
      onDecodeImage,
    );
  }

  return DetectResults(
    results: detectPixels(
      pixels: rotated.pixels ?? Uint8List(0),
      pixelFormat: PixelFormat.bgra,
      width: rotated.width,
      height: rotated.height,
    ),
    image: rotated,
  );
}