Android realizes the function of scanning and identifying numbers

1. Preparation

2. Implementation details

1. The first is the usage of Tess two.

The configuration of build.gradle under app is as follows

Identification method:

Training data can be downloaded in tessdata, which contains various languages. Of course, you can train it yourself. If you are interested, you can learn about it.

2. From the usage of tests two, we can know that what we finally need is a bitmap to identify the picture. In the code scanning project, we find that in the decode method of the decodehandler class, we will get an instance of the planaryuvluminancesource class. The hybridbinarizer algorithm is used to analyze the data source, and finally the multiformatreader is used to analyze the image to get the results. The code is roughly as follows:

After reading it, I was stunned. There was no bitmap. After some searching, it is found that the planaryuvluminancesource class in the old version of zxing has the rendercroppedgreyscalebitmap method, which is removed for some reason...

3. After that, the parameter information of some cameras was modified to adapt the preview effect of some devices. The basic page has been modified. I won't repeat it here.

Take a wave, the following effects:

It can be found that in addition to numbers, it recognizes Chinese as letters. In fact, the first problem is that we use English training data and set the letters a ~ Z in the white list. Of course, you can't set letters as a blacklist, which will only make unrecognized characters recognized as messy numbers.

My suggestion here is to use regular to filter, so that you can identify the data in various formats you want. I just did a simple identification of mobile phone number here. You can draw inferences from one example.

After modification, it is as follows: (multiple numbers are supported at the same time)

Of course, this project also retains the code scanning function (you can add the barcode format in the decodehandler):

Careful students can see from the picture that the size of the scanning frame is different. Here I changed it to a scanning frame that can be adjusted manually. After all, in the code scanning mode, it is better to identify a larger box (it sometimes takes time to put the QR code into the box). When scanning numbers and words, a smaller box will be easy to identify. You can download it for your own experience.

Finally, I uploaded the code to GitHub: Tesseract OCR scanner

summary

The above is what Xiaobian introduced to you. Android realizes the function of scanning and identifying numbers. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>