gpt4 book ai didi

android - 字符/单词的坐标[OCR应用]

转载 作者:行者123 更新时间:2023-12-02 17:08:02 27 4
gpt4 key购买 nike

因此,基本上,我正在创建一个android应用程序(使用tesseract和OpenCV),当在预处理和扫描步骤后给定单词时,在该单词周围绘制一个矩形-基本上是“查找”该单词并将其标记出来。但是我想知道如何获取角色的坐标?还是至少一个字?我有每行的坐标,但是这些坐标不是相对于“主画面”的坐标,而是相对于我拥有的“文本块”的坐标。也许有人拥有/知道解释/教程或某种有关如何找到单词/字符坐标的信息。高度赞赏。

最佳答案

此示例代码来自tesseract的API Examples Wiki页面,应有助于:
APIExamples

专注于这两行: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)));
}

关于android - 字符/单词的坐标[OCR应用],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50474370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com