首先,我想确认我理解选择迭代器的权利。
例如,如果我在图像“范围”上有一个单词,
选择迭代器必须给我类似“s”的东西,也许在Next(),“5”之后。
对于3.字母“o”它可能给我“0”,在Next()“O”之后和Next()“o”之后。
我理解对吗?
这是我所有相关的代码,
api.SetImage((uchar*)img->imageData,img->width,img->height,img->depth/8,img->widthStep);
api.SetRectangle(0,0,img->width, img->height);
int left,top,right,bottom;
left=0;top=0;right=0;bottom=0;
api.Recognize(NULL);
tesseract::ResultIterator *ri=api.GetIterator();
tesseract::ChoiceIterator *choiceItr;
const tesseract::ResultIterator itr = *ri;
choiceItr = new tesseract::ChoiceIterator(itr);
const char * out=choiceItr->GetUTF8Text();
char * out2=(*ri).GetUTF8Text(tesseract::RIL_SYMBOL);
printf("out:%s,out2:%s",out,out2);
控制台上的输出是:
日期:(空),OUT2:P
p是预期的结果迭代器结果,但是选择迭代器输出为空。
感谢您的想法。
大致解决了:
// This ensures Tesseract's "blob_choices" structures are filled
SetVariable("save_best_choices", "T");
答案 0 :(得分:5)
如果您还没有找到解决方案,以下代码将演示如何迭代所有字符(使用ResultIterator
)及其最佳替代方法(使用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)));
}