detect method

Future<List<Animal>> detect(
  1. Uint8List imageBytes
)

Detects animals in an image from raw bytes.

Decodes the image bytes using OpenCV and runs the detection pipeline.

Returns a list of Animal objects. Returns an empty list if image decoding fails or no animals are detected.

Throws StateError if called before initialize.

Implementation

Future<List<Animal>> detect(Uint8List imageBytes) async {
  if (!_isInitialized) {
    throw StateError(
        'AnimalDetector not initialized. Call initialize() first.');
  }
  try {
    final mat = cv.imdecode(imageBytes, cv.IMREAD_COLOR);
    if (mat.isEmpty) return <Animal>[];
    try {
      return await detectFromMat(
        mat,
        imageWidth: mat.cols,
        imageHeight: mat.rows,
      );
    } finally {
      mat.dispose();
    }
  } catch (e) {
    return <Animal>[];
  }
}