detectFacesFromMatBytes method

Future<List<Face>> detectFacesFromMatBytes(
  1. Uint8List bytes, {
  2. required int width,
  3. required int height,
  4. int matType = 16,
  5. FaceDetectionMode mode = FaceDetectionMode.full,
})

Detects faces from raw pixel bytes without constructing a cv.Mat first.

This avoids the overhead of building a Mat on the calling thread - the bytes are transferred via zero-copy TransferableTypedData and the Mat is reconstructed inside the background isolate.

Parameters:

  • bytes: Raw pixel data (e.g. BGR, BGRA)
  • width: Image width in pixels
  • height: Image height in pixels
  • matType: OpenCV MatType value (default: CV_8UC3 = 16 for BGR)
  • mode: Detection mode controlling which features to compute

Throws StateError if initialize has not been called successfully.

Implementation

Future<List<Face>> detectFacesFromMatBytes(
  Uint8List bytes, {
  required int width,
  required int height,
  int matType = 16,
  FaceDetectionMode mode = FaceDetectionMode.full,
}) async {
  _requireReady();
  final List<dynamic> result = await _sendDetectionRequest<List<dynamic>>(
    'detectMat',
    {
      'bytes': TransferableTypedData.fromList([bytes]),
      'width': width,
      'height': height,
      'matType': matType,
      'mode': mode.name,
    },
  );
  return _applyGates(_deserializeFacesFast(result));
}