blinkid-ios
blinkid-ios copied to clipboard
Restricting the analyzed document type
Environment
- Xcode version: 11.4
- BlinkID SDK version: 5.2
- What are you trying to scan? Driving license and ID card.
Describe the problem
We would like to recognize only driving licenses or at least have a way to differentiate between a driving license and another kind of document, like an ID card.
The MBDriverLicenseDetailedInfo
is not nil
for non-driving-license documents, and therefore there's no way to differentiate from each other.
Hi @kikettas
The following feature you are asking about is currently not supported in BlinkID. However, in the upcoming release (5.4.0) there will be an option to get the document type when scanning various samples. With that feature, you can differentiate what type of document you are scanning, along with the country from where the document is from.
I hope this helped. If you have any further questions, feel free to ask or contact us directly at [email protected]
Regards, Milan
Hi @mparadina,
Thanks for the quick response. Do you know when is the 5.4.0
update will be available?
Best, Enrique.
HI @kikettas,
We plan for the release by the end of April.
If there's a need for a quick workaround, we can try working something out. BlinkID Recognizer can be used to scan many different types of documents. If you're only scanning Spanish documents (this we're limiting with a license key which only grants rights to scan Spanish documents), maybe there are other fields that we can use for differentiation? Spanish DLs (and many other EUDLs) don't have 'sex' property, for example. So when you get a valid scanning result, and it doesn't have a 'sex' property set, this might indicate we scanned a DL.
Jurica.
Alright, we might want to release a quick workaround soon so if you tell us which parameters should we check in the recognizer result, we'll implement asap until you release the 5.4.0
.
Hi @kikettas
Ok, since you're scanning only Spanish documents, here's something that might work.
func blinkIdOverlayViewControllerDidFinishScanning(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController, state: MBRecognizerResultState) {
/** This is done on background thread */
blinkIdOverlayViewController.recognizerRunnerViewController?.pauseScanning()
var message: String = ""
var title: String = ""
if (self.blinkIdRecognizer?.result.resultState == MBRecognizerResultState.valid) {
let sex = self.blinkIdRecognizer?.result.sex
let scannedDocumentWasDL = ((sex ?? "").isEmpty)
if (scannedDocumentWasDL) {
title = "Spanish DL"
} else {
title = "Spanish ID"
}
// Save the string representation of the code
message = self.blinkIdRecognizer!.result.description
/** Needs to be called on main thread beacuse everything prior is on background thread */
DispatchQueue.main.async {
// present the alert view with scanned results
let alertController: UIAlertController = UIAlertController.init(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
let okAction: UIAlertAction = UIAlertAction.init(title: "OK", style: UIAlertAction.Style.default,
handler: { (action) -> Void in
self.dismiss(animated: true, completion: nil)
})
alertController.addAction(okAction)
blinkIdOverlayViewController.present(alertController, animated: true, completion: nil)
}
} else {
blinkIdOverlayViewController.recognizerRunnerViewController?.resumeScanningAndResetState(false)
}
}
The key part is analysing the sex
property to distinguish between ID and DL.
Just to explain. I really wouldn't recommend this in general, because it's a pretty dirty solution. But in your case, where you only scan Spanish IDs and DLs, and while you're waiting for v5.4, this might be an OK workaround. I hope you understand.
Stay safe! Jurica.
Hi @Cerovec,
Alright, we'll carry out that approach until you release the new version of the library. Thanks for your help.
Stay safe you too! Best, Enrique.
Ok, no problem. We'll keep this issue open and revisit when we release the actual new feature.
If you want to be notified immediately when we release the new SDK, you can "star" this repo.
Also, the same workaround and the same feature for v5.4 we also plan for Android, in the same timeframe.
Best, Jurica.
Hi @kikettas,
Just to keep you in the loop - we're on track with our planned release v5.4 and this specific feature. We're planning it for the 1st of May.
We'll definitely follow up here once we release the update.
Thanks, Jurica.
Hi @kikettas,
please check out version 5.4 - it's out.
https://github.com/BlinkID/blinkid-ios/releases/tag/v5.4.0
Thanks, Jurica.
Cool, we’ll jump into it soonish 🎊 Thanks for proactively keeping me posted! 💯
Hi @Cerovec,
So the new way of checking if it's a driving license should be something like this, right?
guard let recognizer = recognizer as? MBBlinkIdRecognizer,
case .typeDl = recognizer.result.classInfo?.type else {
/// Not a Driving license
}
/// It's a driving license!
Hi @kikettas
With this approach, you are not filtering when scanning, but after scanning.
Correct way to filter what you want to scan while scanning is to conform to MBBlinkIdRecognizerDelegate
-> recognizer.classFilterDelegate = self
and implement classInfoFilter
method which returns MBClassInfo
object and you just need to return true/false based on what type of document you want to scan. When you do this, if returned false
, scanning will not complete.
Alright, didn't know that approach. Thanks a lot! 💯
By the way, should we consider this issue closed?
Last but not least, is there a way to convert an MBCountry
to its country code string value?
Hi @kikettas,
sorry for the delay. Unfortunately, there's no built in way to convert between the code and a string. :/
Is this necessary for your use case?
And yes, can we close this specific issue now? :)
Best, Jurica.
Hi everyone,
Closing the issue as it is inactive. Feel free to reopen it, or create a new issue if anything comes up!