initializeFromBuffers method
Future<void>
initializeFromBuffers({
- required Uint8List palmDetectionBytes,
- required Uint8List handLandmarkBytes,
- Uint8List? gestureEmbedderBytes,
- Uint8List? gestureClassifierBytes,
- HandMode mode = HandMode.boxesAndLandmarks,
- HandLandmarkModel landmarkModel = HandLandmarkModel.full,
- double detectorConf = 0.45,
- double palmNmsIou = 0.45,
- double palmRoiScale = 2.6,
- int maxDetections = 10,
- double minLandmarkScore = 0.5,
- bool enableTracking = false,
- TrackingConfig trackingConfig = const TrackingConfig(),
- int interpreterPoolSize = 1,
- PerformanceConfig performanceConfig = const PerformanceConfig(),
- bool enableGestures = false,
- double gestureMinConfidence = 0.5,
- bool useCompiledModel = false,
- Set<
Accelerator> accelerators = const {Accelerator.gpu, Accelerator.cpu}, - Precision precision = Precision.fp16,
Initializes the hand detector from pre-loaded model bytes.
Used when asset loading from the main isolate is not available, or when bytes have already been loaded. Spawns the background isolate with the provided model data.
Parameters:
palmDetectionBytes: Raw bytes of the palm detection TFLite modelhandLandmarkBytes: Raw bytes of the hand landmark TFLite modelgestureEmbedderBytes: Raw bytes of the gesture embedder model (optional; required for gesture recognition)gestureClassifierBytes: Raw bytes of the gesture classifier model (optional; required for gesture recognition)mode: Detection mode. Default: HandMode.boxesAndLandmarkslandmarkModel: Hand landmark model variant. Default: HandLandmarkModel.fulldetectorConf: Palm detection confidence threshold. Default: 0.45palmNmsIou: IoU threshold for palm non-maximum suppression. Default: 0.45palmRoiScale: Expansion factor for the palm ROI fed to the landmark model. Default: 2.6trackingConfig: ROI tuning used whenenableTrackingis true. Default: TrackingConfigmaxDetections: Maximum number of hands to detect. Default: 10minLandmarkScore: Minimum landmark confidence score. Default: 0.5interpreterPoolSize: Number of landmark model interpreter instances. Default: 1. Forced to 1 when a performance delegate (XNNPACK/auto) is enabled.performanceConfig: TensorFlow Lite performance configuration. Default: autoenableGestures: Whether to run gesture recognition. Default: falsegestureMinConfidence: Minimum confidence for gesture recognition. Default: 0.5
Implementation
Future<void> initializeFromBuffers({
required Uint8List palmDetectionBytes,
required Uint8List handLandmarkBytes,
Uint8List? gestureEmbedderBytes,
Uint8List? gestureClassifierBytes,
HandMode mode = HandMode.boxesAndLandmarks,
HandLandmarkModel landmarkModel = HandLandmarkModel.full,
double detectorConf = 0.45,
double palmNmsIou = 0.45,
double palmRoiScale = 2.6,
int maxDetections = 10,
double minLandmarkScore = 0.5,
bool enableTracking = false,
TrackingConfig trackingConfig = const TrackingConfig(),
int interpreterPoolSize = 1,
PerformanceConfig performanceConfig = const PerformanceConfig(),
bool enableGestures = false,
double gestureMinConfidence = 0.5,
bool useCompiledModel = false,
Set<Accelerator> accelerators = const {Accelerator.gpu, Accelerator.cpu},
Precision precision = Precision.fp16,
}) async {
if (isReady) {
throw StateError('HandDetector already initialized');
}
final effectivePoolSize = performanceConfig.mode == PerformanceMode.disabled
? interpreterPoolSize
: 1;
final worker = _HandDetectorWorker();
try {
await worker.initialize(
palmDetectionBytes: palmDetectionBytes,
handLandmarkBytes: handLandmarkBytes,
gestureEmbedderBytes: gestureEmbedderBytes,
gestureClassifierBytes: gestureClassifierBytes,
mode: mode,
landmarkModel: landmarkModel,
detectorConf: detectorConf,
palmNmsIou: palmNmsIou,
palmRoiScale: palmRoiScale,
maxDetections: maxDetections,
minLandmarkScore: minLandmarkScore,
enableTracking: enableTracking,
trackingConfig: trackingConfig,
interpreterPoolSize: effectivePoolSize,
performanceConfig: performanceConfig,
enableGestures: enableGestures,
gestureMinConfidence: gestureMinConfidence,
useCompiledModel: useCompiledModel,
accelerators: accelerators,
precision: precision,
);
} catch (e) {
if (worker.isReady) {
await worker.dispose();
}
rethrow;
}
_worker = worker;
}