简体   繁体   中英

blacklist and whitelist in tesseract ANDROID

I am developing an android application that recharge phone with credit by taking picture of the card by phone's camera or from the gallery..I used tesseract library for this purpose to take only the digits using blacklist and whitelist.. it does not work as expected

the picture I used contains these two lines only:

PIN code

41722757649786

the result before starting the recharge activity was:

718 200

41722757649786

I want to recognize only the digits without letters and without using cropper..

  public void initTess(){   

    if (mBaseApi != null)
        mBaseApi.end();     

    mBaseApi = new TessBaseAPI();
    mBaseApi.setDebug(false);

    mBaseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_OSD_ONLY);
    mBaseApi.init(mDataDir + File.separator,"eng");
    mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"0123456789");
    mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz");


}

Setting the "tessedit_char_whitelist" variable must be done BEFORE the init, as stated in the FAQ : https://code.google.com/p/tesseract-ocr/wiki/FAQ#How_do_I_recognize_only_digits ? This most likely hold true for the blacklist as well.

Therefore, changing your code from this :

mBaseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_OSD_ONLY);
mBaseApi.init(mDataDir + File.separator,"eng");
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"0123456789");
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz");

to this :

mBaseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_OSD_ONLY);
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"0123456789");
mBaseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz");
mBaseApi.init(mDataDir + File.separator,"eng");

should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM