detectFromMat method

Future<List<Hand>> detectFromMat(
  1. Mat image
)

Detects hands in a pre-decoded cv.Mat image.

The Mat's raw pixel data is extracted and transferred to the background isolate using zero-copy TransferableTypedData. The original Mat is NOT disposed by this method; the caller is responsible for disposal.

Throws StateError if called before initialize.

Implementation

Future<List<Hand>> detectFromMat(cv.Mat image) {
  if (!isReady) {
    throw StateError(
        'HandDetector not initialized. Call initialize() first.');
  }
  // A non-continuous Mat (e.g. a region()/ROI view) yields scrambled bytes
  // from .data, which reads total*elemSize contiguous bytes and ignores row
  // stride. Clone to a continuous copy first; detectFromMatBytes copies the
  // bytes into a TransferableTypedData synchronously, so the clone can be
  // disposed immediately after.
  final cv.Mat src = image.isContinuous ? image : image.clone();
  final result = detectFromMatBytes(
    src.data,
    width: src.cols,
    height: src.rows,
    matType: src.type.value,
  );
  if (!identical(src, image)) src.dispose();
  return result;
}