所以基本上,我正在创建一个Android应用程序(使用tesseract和OpenCV),当在预处理和扫描步骤后给出一个单词时,在该单词周围绘制一个矩形 - 基本上“找到”该单词并标记它。但是我想知道如何获得角色的坐标?或至少一个字?我有每条线的坐标,但坐标不是相对于“主图片”,而只是我所拥有的“文本块”的坐标。也许某人已经/知道解释/教程或某些关于如何寻找单词/字符坐标的信息。非常感谢。
答案 0 :(得分:1)
此示例代码取自tesseract的API Examples Wiki页面,应该有助于: APIExamples
专注于这2行:
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
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);
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
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)));
}