简体   繁体   English

tesseract ANDROID中的黑名单和白名单

[英]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 我正在开发一个Android应用程序,通过电话的相机或从画廊拍照卡来为信用卡充值。我使用tesseract库为此目的只使用黑名单和白名单的数字..它不能按预期工作

the picture I used contains these two lines only: 我使用的图片仅包含这两行:

PIN code PIN码

41722757649786 41722757649786

the result before starting the recharge activity was: 开始充电活动之前的结果是:

718 200 718 200

41722757649786 41722757649786

I want to recognize only the digits without letters and without using cropper.. 我想只识别没有字母的数字而不使用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 ? 设置"tessedit_char_whitelist"变量必须在初始化之前完成,如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. 应该做的伎俩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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