Skip to main content

Improving Accuracy with Multiple Scans

To improve OCR accuracy, the SDK provides a feature that determines whether the same text has been read consecutively across multiple frames.

Setting the Number of Reads​

Use ModelSettings to configure the number of consecutive reads required. The default is 1.

// Confirm after reading the same content 5 times
let modelSettings = ModelSettings(textNToConfirm: 5)

Checking the Confirmation Status​

Use the getStatus() method of Detection to check whether the status is ScanConfirmationStatus.Confirmed.

if status == ScanConfirmationStatus.Confirmed {
let bbox = detection.getBoundingBox()
drawDetection(bbox: bbox, text: text)
}

TextMapper​

During multiple reads, camera shake or movement can cause slight variations in the recognition results, which resets the confirmation count. You can use a TextMapper to normalize the recognition results and mitigate this issue.

Subclass the TextMapper class and implement the map (iOS) / apply (Android) method. The following example converts letters and symbols to digits when reading postal codes.

class PostcodeTextMapper: TextMapper {
let regex = /^\D*(\d{3})-(\d{4})\D*$/

override func map(_ text: Text) -> String {
var t = text.getText()
t = t.replacingOccurrences(of: "A", with: "4")
t = t.replacingOccurrences(of: "B", with: "8")
t = t.replacingOccurrences(of: "b", with: "6")
t = t.replacingOccurrences(of: "O", with: "0")
t = t.replacingOccurrences(of: "o", with: "0")
t = t.replacingOccurrences(of: "I", with: "1")
t = t.replacingOccurrences(of: "l", with: "1")
t = t.replacingOccurrences(of: "S", with: "5")
t = t.replacingOccurrences(of: "Z", with: "2")
// ... other conversions

if let match = t.wholeMatch(of: regex) {
t = String(match.1) + "-" + String(match.2)
}
return t
}
}

Configuration:

let modelSettings = ModelSettings(textNToConfirm: 5)
modelSettings.setTextMapper(PostcodeTextMapper())