Tesseract变量“save_blob_choices”如何工作?

问题描述 投票:3回答:1

所以我一直在尝试使用tesseract ocr(特别是tess-two)来安装一个android项目来扫描一些符号。

一切正常,但有时识别的String返回null。我找到的解决方案之一是将变量save_blob_choices设置为true,以便让tesseract保存替代识别。

但我不知道它是否应该这样做。它在哪里节省了替代品?我如何访问它们?

当然,如果除了使用此变量之外还有其他任何解决方案,请告诉我。

这是我的代码:

TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(MainActivity.DATA_PATH, MainActivity.lang);
baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR);


baseApi.setVariable("tessedit_char_whitelist","abcdefghijklmnopqrst");
baseApi.setVariable("save_blob_choices", "T");

baseApi.setImage(mainBitmap);

publishProgress(80);


mainBitmap.recycle();
mainBitmap = null;

// Iterate through the results.
ResultIterator iterator = baseApi.getResultIterator();
String lastUTF8Text;
float lastConfidence;


iterator.begin();
do {
    lastUTF8Text = iterator.getUTF8Text(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL);
    lastConfidence = iterator.confidence(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL);

    Log.i("string, intConfidence",lastUTF8Text+", "+lastConfidence);
} while (iterator.next(TessBaseAPI.PageIteratorLevel.RIL_SYMBOL));


baseApi.end();

另外作为一个额外的问题,base.setDebug(true)应该工作吗?因为它似乎没有做任何事情。

android blob ocr tesseract tess-two
1个回答
0
投票

请查看以下示例。 https://github.com/tesseract-ocr/tesseract/wiki/APIExample

迭代器的示例,用于单个符号的分类器选项

Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif");
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "eng");
api->SetImage(image);
api->SetVariable("save_blob_choices", "T");
api->SetRectangle(37, 228, 548, 31);
api->Recognize(NULL);

tesseract::ResultIterator* ri = api->GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
if(ri != 0) {
    do {
        const char* symbol = ri->GetUTF8Text(level);
        float conf = ri->Confidence(level);
        if(symbol != 0) {
            printf("symbol %s, conf: %f", symbol, conf);
            bool indent = false;
            tesseract::ChoiceIterator ci(*ri);
            do {
                if (indent) printf("\t\t ");
                printf("\t- ");
                const char* choice = ci.GetUTF8Text();
                printf("%s conf: %f\n", choice, ci.Confidence());
                indent = true;
            } while(ci.Next());
        }
        printf("---------------------------------------------\n");
        delete[] symbol;
    } while((ri->Next(level)));
}
© www.soinside.com 2019 - 2024. All rights reserved.