无法在tesseract中使用ChoiceIterator [英] Can not use ChoiceIterator in tesseract
问题描述
首先,我想确认我了解选择迭代器的正确性.
First of all i want to confirm that i understand choice iterator right.
例如,如果我在图像范围"上有一个字,
For example if i have a word on an image "scope",
选择迭代器必须给我类似"s"的内容,并且可能要在Next()之后加上"5".
choice iterator must give me something like "s" and maybe after Next(), "5".
对于3.字母"o",在Next()"O"之后和Next()"o"之后,它可能会给我"0".
for 3. letter "o" it maybe gives me "0", after Next() "O" and after Next() "o".
我明白吗?
这是我所有相关的代码,
Here is all my related code,
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);
控制台上的输出是:
out:(null),out2:P
out:(null),out2:P
p是预期的结果迭代器结果,但选择迭代器输出为null.
p is expected result iterator result, but choice iterator output is null.
感谢创意.
已解决:
// This ensures Tesseract's "blob_choices" structures are filled
SetVariable("save_best_choices", "T");
http://code.google.com/p/tesseract-ocr/issues/detail?id = 555
推荐答案
如果您尚未找到解决方案,则以下代码显示如何遍历所有字符(使用ResultIterator
)及其最佳选择(使用ChoiceIterator
).
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)));
}
这篇关于无法在tesseract中使用ChoiceIterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!