setConfidenceThreshold method

Future<void> setConfidenceThreshold(
  1. double threshold
)

Sets the confidence threshold for object detection.

Only detections with confidence scores above threshold will be returned. The value is automatically clamped between 0.0 and 1.0.

Example:

// Only show detections with 70% confidence or higher
await controller.setConfidenceThreshold(0.7);

Implementation

Future<void> setConfidenceThreshold(double threshold) async {
  final clampedThreshold = threshold.clamp(0.0, 1.0);
  _confidenceThreshold = clampedThreshold;
  if (_methodChannel == null) {
    logInfo(
      'YOLOViewController: Warning - Cannot apply confidence threshold, view not yet created',
    );
    return;
  }
  try {
    await _methodChannel!.invokeMethod('setConfidenceThreshold', {
      'threshold': clampedThreshold,
    });
    logInfo(
      'YOLOViewController: Applied confidence threshold: $_confidenceThreshold',
    );
  } catch (e) {
    logInfo('YOLOViewController: Error applying confidence threshold: $e');
    return _applyThresholds();
  }
}