Can not use ChoiceIterator in tesseract

浪尽此生 提交于 2019-12-04 17:32:17

In case you haven't found a solution yet, the following code shows how to iterate over all characters (using ResultIterator) and its best alternatives (using ChoiceIterator).

tess.SetVariable("save_best_choices", "T"); 
tess.SetImage(...); 
tess.Recognize(0); 

tesseract::ResultIterator* ri = tess.GetIterator();
tesseract::ChoiceIterator* ci; 

if(ri != 0)
{
    do
    {
        const char* symbol = ri->GetUTF8Text(tesseract::RIL_SYMBOL);

        if(symbol != 0)
        {
            float conf = ri->Confidence(tesseract::RIL_SYMBOL); 
            std::cout << "\tnext symbol: " << symbol << "\tconf: " << conf << "\n"; 

            const tesseract::ResultIterator itr = *ri; 
            ci = new tesseract::ChoiceIterator(itr);

            do
            {
                const char* choice = ci->GetUTF8Text(); 
                std::cout << "\t\t" << choice << " conf: " << ci->Confidence() << "\n"; 
            }
            while(ci->Next()); 

            delete ci; 
        }

        delete[] symbol;
    }
    while((ri->Next(tesseract::RIL_SYMBOL)));
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!