On-Device Text Recognition for Identity Verification in Android
Welcome again! Let’s continue our journey of building a seamless Android experience.
One use case that is particularly interesting to be explored in the mobile journey is identity verification. Usually we can verify user identity by just simply asking them to upload a picture of their national identity card/driver license, making sure that the user is using their real identity and not a fraud/bot.
Our use case app, the Bobobox app, works similarly! As you can see in the image below, users can verify their identity by taking a picture of their national ID card and then uploading it to be verified by an admin.
This flow works well for normal cases. However, what happens if the picture taken by the user is blurred and the texts cannot be read? The admin needs to reject the verification request and ask the user to take a better picture. This process consumes more time and may frustrate the user.
There’s one good solution to this problem: On-Device Text Recognition.
With on-device text recognition, we can make sure that the pictures taken by users are high-quality, in the sense that they contain the texts needed for the verification process, preventing “bad” pictures from being uploaded to the server in the first place.
How to Implement On-Device Text Recognition?
Here are the steps needed to implement on-device text recognition in your app. We are going to use Google MLKit for this example.
1. Add the below dependencies to your
app/build.gradle file. Don’t forget to Sync your project afterwards.
2. Next, we need to add a
meta-data in your
AndroidManifest.xml file so that your app automatically downloads the necessary ML model after the user installs your app from the Play Store.
3. There are a lot of input types that you can use for text recognition, but here we are going to use a File URI. As you can see in the code snippet below, once you‘ve done processing the input, you can determine whether the image is good or not based on the extracted text. In this example, an image’s quality is deemed good if it contains the word “national id”. However, you can customize this criteria however you wish. And you can go even further by parsing the blocks, lines, and elements.
4. And, you’re done! That’s one way of utilizing text recognition for identity verification. With this new feature, our app doesn’t just take a picture and upload it to the server, but also decides whether the picture taken is good enough to be uploaded or not.
Of course, you can tweak and explore this basic concept even further and come up with a lot of more interesting stuff!
Do you Like this Article?
Leave us some claps 👏 and follow our Medium publication for more articles like this.
And don’t forget to download our app on your Android or iOS and book your first room in Bobobox! 😀