Skip to main content

Detector Settings

experimental

The settings on this page are experimental and may change in future versions. See Overview of Experimental Features for details.

Through ModelSettings, you can fine-tune how detectors (the models that find the positions of text and barcodes in an image) behave.

Confidence threshold of the YotsukaD detection model​

confidenceThreshold in YotsukaDDetectorSettings sets the minimum confidence for the YotsukaD detection model to detect a barcode. The YotsukaD detection model is used by barcode_next.

FieldDefaultDescription
confidenceThreshold0.3Detection confidence threshold (0.0–1.0). Lower values find more barcodes but also more false detections. Higher values reduce false detections but miss more barcodes.

A value outside this range causes an error when the model is loaded.

var modelSettings = ModelSettings()
modelSettings.yotsukaDDetectorSettings = YotsukaDDetectorSettings(confidenceThreshold: 0.5)
let modelInfo = try await edgeOCR.useModel(model, settings: modelSettings)

Post-processing of text detection results​

postProcessing in DBTextDetectorSettings sets the post-processing applied to the output of the text detection model. It applies to text detection in all OCR models (such as model-d320x320).

ValueDescription
None (default)No post-processing.
OpeningClosingApplies morphological opening and closing to the detection result, removing small noise and filling gaps.
HorizontalMerger84Joins characters separated by horizontal gaps so they are detected as a single string. Useful when a string with wide character spacing is split partway through.

HorizontalMerger84 may also join separate strings that sit side by side. Check it with your actual targets before using it.

The following example sets HorizontalMerger84.

var modelSettings = ModelSettings()
// Swift requires every field, so the fields other than postProcessing use their defaults
modelSettings.dbTextDetectorSettings = DBTextDetectorSettings(
binaryThreshold: 0.3,
widthFactor: 1.5,
heightFactor: 3.0,
postProcessing: .HorizontalMerger84)
let modelInfo = try await edgeOCR.useModel(model, settings: modelSettings)