Page: OCR library for iOS
2021-12-20 17:12
OCR library for iOS
Installation
- Add
SESmartID
folder containing source files to your project, select Create groups in the menu - Add
SESmartIDCore/lib
folder containing static library to your project, select Create groups in the menu - Add
SESmartIDCore/data-zip
folder to your project, select Create folder references in the menu - Add
SESmartIDCore/include
folder to the Header Search Paths in project settings - Add
SESmartIDCore/wrap
folder containing core library wrappers, select Create groups in the menu. - Add
SESmartIDCore/wrap/objcsecommon/include
,SESmartIDCore/wrap/objcsecommon/include_impl
,SESmartIDCore/wrap/objcidengine/include
,SESmartIDCore/wrap/objcidengine/include_impl
folders to the Header Search Paths in your project settings - If you use Swift, add
SESmartID/SmartID-Bridging-Header.h
to the Objective-C Bridging Header in project settings
Basic usage
1. Create IdEngine instance
After installing the framework first you need to initialize the OCR engine:
var idEngine = SmartIDVideoProcessingEngineSwift()
Configuration process might take a while but it only needs to be performed once during the program lifetime. Configured IdEngine
is used to spawn IdSessions
which have actual recognition methods.
2. Setup IdEngine
You should setup the IdEngine instance setting its delegate and the signature provided with the library.
Smart ID Engine users are required to use a personalized signature for starting a session. The signature is validated offline and locks to the copy of the native library, thus ensures that only an authorized client may use it. The signature is a string with 256 characters which you may find in the provided documentation or request from the library provider.
You will need to manually copy the signature string and pass it to the idEngine instance (see below). Do NOT keep the signature in any asset files, only inside code. If possible, clients are encouraged to keep the signature in a controlled server and load it into the application via a secure channel, to ensure that signature and the library are separated.
let signature = "<YOUR_SIGNATURE_GOES_HERE>"
idEngine.sessionOption(withOptionName: "signature", andWithOptionValue: signature)
To set the Smart ID Engine delegate you should create an object conforming to SmartIDVideoProcessingEngineSwiftDelegate
:
class SmartIDDelegate: SmartIDVideoProcessingEngineSwiftDelegate {
func smartIDVideoProcessingEngineDidRecognize(_ result: SmartIDRecognitionResult) {
// ...
}
}
instantiate your new SmartIDDelegate
:
let smartIDDelegate = SmartIDDelegate()
and set the desired delegate object to idEngine
instance smartIDDelegate
property:
idEngine.smartIDDelegate = smartIDDelegate
For further information and delegate options see
SmartIDVideoProcessingEngineSwiftDelegate
implementation. The described implementation is enough for the majority of usecases.
3. Setup OCR session
The next step allows you to specify the desired document types for recognition:
let sessionSettings = self.idEngine.getSessionSettings()
sessionSettings.addEnabledDocumentTypes("bra.id.type1")
By default, all document types are disabled.
For the whole list of supported document types please see the full library documentation — List of countries and special document types
In a single session you can only enable document types that belong to the same internal engine.
For convenience it's possible to use wildcards (using asterisk symbol) while enabling or disabling document types.
sessionSettings.addEnabledDocumentTypes("bra.*")
It's always better to enable the minimum number of document types as possible if you know exactly what are you going to recognize because the system will spend less time deciding which document type out of all enabled ones has been presented to it.
4. Process image
After setting up the engine, session and delegate methods, the final step is to call one of the process...
methods:
idEngine.processUIImageFile(documentImage)
5. Process OCR results
In the smartIDVideoProcessingEngineDidRecognize
delegate method you should have result
available after succesful recognition.
You can get the recognized document type as follows:
let documentType = result.getDocumentType()
as well as you have an access to the recognized fields using the following methods:
let stringFields = result.getStringFields()
let imageFields = result.getImageFields()
As a result you get an array of SmartIDStringField
or SmartIDImageField
objects. Each object gives you:
- the name of the field —
getName()
- the value of the field —
getValue()
- the confidence of the OCR —
getConfidence()