How to Implement the Automatic Bill Number Input Function Using HUAWEI ML Kit’s Text Recognition
In this post, I will show you how to implement automatic input of bill numbers and discount codes using HUAWEI ML Kit’s text recognition function.
Join the DZone community and get the full member experience.Join For Free
Text recognition is useful in a huge range of situations. For example, if you scan the following bill, indicate that the bill service number starts with “NO.DE SERVICIO”, and limit the length to 12 characters, you can quickly get the bill service number “123456789123” using the text recognition.
Similarly, if you scan the discount coupon below, start the discount code with “FAVE-” and limit the length to four characters, you’ll get the discount code “8329”, and can then complete the payment.
Pretty useful, right? You can also customize the information you want your app to recognize.
Integrating Text Recognition
So, let’s look at how to process bill numbers and discount codes.
You can find detailed information about the preparations you need to make on the HUAWEI Developer.
Here, we’ll just look at the most important procedures.
1.1 Configure the Maven repository address in the project-level build.gradle file.
1.2 Add configurations to the file header.
Once you’ve integrated the SDK, add the following configuration to the file header:
1.3: Configure SDK dependencies in the app-level build.gradle file.
1.4: Add these statements to the AndroidManifest.xml file so the machine learning model can automatically update.
1.5: Apply for the camera permission.
2. Code Development
2.1: Create an analyzer.
2.2: Set the recognition result processor to bind with the analyzer.
2.3: Call the synchronous API.
Use the built-in LensEngine of the SDK to create an object, register the analyzer, and initialize camera parameters.
2.4: Call the run method to start the camera and read the camera streams for the recognition.
2.5: Process the recognition result as required.
2.6: Stop the analyzer and release the detection resources when the detection ends.
And that’s it! Remember that you can expand this capability if you need to. Now, let’s look at how to scan travel bills.
And here’s how to scan discount codes to quickly obtain online discounts and complete payments.
The GitHub source code can be found here.
Opinions expressed by DZone contributors are their own.