blinkid-ios icon indicating copy to clipboard operation
blinkid-ios copied to clipboard

Restricting the analyzed document type

Open kikettas opened this issue 4 years ago • 16 comments

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.

kikettas avatar Mar 31 '20 11:03 kikettas

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

mparadina avatar Mar 31 '20 13:03 mparadina

Hi @mparadina,

Thanks for the quick response. Do you know when is the 5.4.0 update will be available?

Best, Enrique.

kikettas avatar Mar 31 '20 14:03 kikettas

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.

Cerovec avatar Mar 31 '20 16:03 Cerovec

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.

kikettas avatar Mar 31 '20 17:03 kikettas

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.

Cerovec avatar Apr 01 '20 07:04 Cerovec

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.

kikettas avatar Apr 01 '20 10:04 kikettas

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.

Cerovec avatar Apr 01 '20 14:04 Cerovec

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.

Cerovec avatar Apr 20 '20 07:04 Cerovec

Hi @kikettas,

please check out version 5.4 - it's out.

https://github.com/BlinkID/blinkid-ios/releases/tag/v5.4.0

Thanks, Jurica.

Cerovec avatar Apr 28 '20 14:04 Cerovec

Cool, we’ll jump into it soonish 🎊 Thanks for proactively keeping me posted! 💯

kikettas avatar Apr 28 '20 14:04 kikettas

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!

kikettas avatar May 11 '20 16:05 kikettas

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.

juraskrlec avatar May 11 '20 17:05 juraskrlec

Alright, didn't know that approach. Thanks a lot! 💯

kikettas avatar May 13 '20 15:05 kikettas

By the way, should we consider this issue closed?

kikettas avatar May 13 '20 15:05 kikettas

Last but not least, is there a way to convert an MBCountry to its country code string value?

kikettas avatar May 13 '20 16:05 kikettas

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.

Cerovec avatar Jun 07 '20 20:06 Cerovec

Hi everyone,

Closing the issue as it is inactive. Feel free to reopen it, or create a new issue if anything comes up!

mparadina avatar Jan 04 '23 07:01 mparadina