Android OCR detecting digits only using popular tessercat fork tess-two

霸气de小男生 提交于 2019-12-04 09:11:10

I wanted to do the same and after a bit of research I decided to capture all, text and numbers, and then just keep the numbers, this is working for me:

//This Replaces all except numbers from 0 to 9    
recognizedText = recognizedText.replaceAll("[^0-9]+", " "); 

And now you can do whatever you want with the numbers.

For example, I use this code to get all the numbers separated into an String array, and show them on a TextView

String[] justnumbers = recognizedText.trim().split(" "); //Deletes blank spaces and splits the numbers
YourTextView.setText(Arrays.toString(justnumbers).replaceAll("\\[|\\]", "")) //sets the numbers into the TextView and deletes the "[]" from the String Array

You can see it working here.

Hope this helps.

I made it a bit different. Maybe it will be useful for somebody.

So you need to initialize first the API.

TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(datapath, language, ocrEngineMode);

Then set the following variables

baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
baseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, "!?@#$%&*()<>_-+=/:;'\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, ".,0123456789");
baseApi.setVariable("classify_bln_numeric_mode", "1");

In this way the engine will check only the numbers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!