callWithIsolate static method
Runs iris detection in a separate isolate for non-blocking inference.
This static method spawns a dedicated isolate to perform iris landmark detection on encoded eye crop image bytes. This is useful for running iris detection without blocking the main UI thread, especially for one-off detections or background processing.
The eyeCropBytes parameter should contain encoded image data (JPEG, PNG)
of a cropped eye region.
The modelPath parameter specifies the filesystem path to the iris model
(.tflite file).
Returns a list of 3D landmark points in normalized coordinates (0.0 to 1.0)
relative to the eye crop, where each point is [x, y, z].
Performance: Creates a new isolate for each call. For repeated detections, prefer creating a long-lived IrisLandmark instance.
Example:
final irisPoints = await IrisLandmark.callWithIsolate(
eyeCropBytes,
'/path/to/iris_landmark.tflite',
);
Throws StateError if the model cannot be loaded or inference fails.
See also:
Implementation
static Future<List<List<double>>> callWithIsolate(
Uint8List eyeCropBytes,
String modelPath,
) async {
final ReceivePort rp = ReceivePort();
final Isolate iso = await Isolate.spawn(IrisLandmark._isolateEntry, {
'sendPort': rp.sendPort,
'modelPath': modelPath,
'eyeCropBytes': eyeCropBytes,
});
final Map<dynamic, dynamic> msg = await rp.first as Map;
rp.close();
iso.kill(priority: Isolate.immediate);
if (msg['ok'] == true) {
final List pts = msg['points'] as List;
return pts
.map<List<double>>(
(e) => (e as List).map((n) => (n as num).toDouble()).toList(),
)
.toList();
} else {
throw StateError(msg['err'] as String);
}
}