Swift
On-Device AI Scanning (OCR)
The Vision SDK allows for on-device AI scanning (OCR), enabling offline extraction of structured information from documents such as shipping labels. This is ideal when low latency and offline functionality are critical, such as in warehouse and logistics environments.
π οΈ Step 1: Preparing On-Device OCR
Before using the on-device OCR, you must prepare the model using the following methods. This ensures the necessary AI models are downloaded and ready to use.
Option 1: Auto Model Size Configuration
If you want Vision SDK to automatically determine the best model size based on your PackageX subscription:
Option 2: Explicit Model Size Configuration
You can also specify the model size manually using .micro
(faster, smaller) or .large
(slower, more accurate):
β οΈ You must wait for the completion block to succeed before proceeding to OCR extraction.
π§© Selecting the Model Type
When preparing for on-device AI scanning, you can choose which document model you want to use by specifying the forModelClass
parameter. This lets the SDK know which type of document youβre scanning so it can load the appropriate AI model.
Here are the supported options:
π¦ For Shipping Labels
Use this to scan and extract structured data from shipping labels.
π For Bill of Lading (BOL)
Use this to extract data from Bill of Lading documents.
π·οΈ For Item Labels
Use this to process and extract structured details from product/item labels.
π·οΈ For Document Classification
Use this to process and extract document type from a document image.
π Make sure the model is prepared successfully before scanning. Each model may vary in size and complexity depending on the document type.
π§ Step 2: Extracting Data from Image
Once the model is prepared successfully, use the following method to perform OCR on a given image.
Parameters:
ciImage
: TheCIImage
you want to process.barcodes
: A list ofString
values representing barcodes detected in the image (if any).completion
: A closure returning the extracted data or error.
π The returned data follows the same structure as the PackageX Cloud OCR API response.