Skip to main content

Reading DPM Codes with AI

This section explains how to read DPM (Direct Part Marking) codes using AI.

Required Model Files

Reading DPM codes with AI uses the barcode_dpm model. Make sure your model includes the following files:

  • composite/barcode_dpm.json
  • detector/barcode_dpm.bin
  • detector/barcode_dpm.json
  • recognizer/barcode_dpm.bin
  • recognizer/barcode_dpm.json

Model Selection​

The AI for DPM code reading is currently an experimental model. Use availableModelsWithExperimental() to retrieve a list that includes experimental models.

let allModels = edgeOCR.availableModelsWithExperimental()
for candidate in allModels {
if candidate.getUID() == "barcode_dpm" {
model = candidate
}
}

Loading the model:

loadModelAndNavigate(
destination: .DPMView,
uid: "barcode_dpm",
experimental: true)

Implementing the Scanner​

DPM code scanning uses the scan method, just like OCR.

func captureOutput(
_ output: AVCaptureOutput,
didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection
) {
let scanResult: ScanResult
do {
scanResult = try edgeOCR.scan(sampleBuffer, viewBounds: viewBounds)
} catch {
os_log("Failed to scan: %@", type: .debug, error.localizedDescription)
return
}

DispatchQueue.main.async { [weak self] in
self?.drawDetections(result: scanResult)
}
}

Scanning DPM Codes and Text Simultaneously​

To scan DPM codes and text at the same time, add composite/hybrid_dpm_text.json to the model directory.

{
"type": "Hybrid",
"barcodeDetectorUid": "barcode_dpm",
"barcodeRecognizerUid": "barcode_dpm",
"textDetectorUid": "detector-d320x320",
"textRecognizerUid": "recognizer"
}

Specify hybrid_dpm_text as the UID in useModel.

loadModelAndNavigate(
destination: .DPMView,
uid: "hybrid_dpm_text",
experimental: true)