【问题标题】:Coordinates of a character/word [OCR app]字符/单词的坐标 [OCR 应用程序]
【发布时间】:2018-05-22 18:36:23
【问题描述】:

所以基本上,我正在创建一个 android 应用程序(使用 tesseract 和 OpenCV),当在预处理和扫描步骤后给出一个单词时,会在该单词周围绘制一个矩形 - 基本上是“找到”单词并标记它。但是我想知道如何获取角色的坐标?或至少一个词?我有每条线的坐标,但坐标与“主图片”无关,而只是我拥有的“文本块”的坐标。也许有人有/知道解释/教程或某种关于如何查找单词/字符坐标的信息。非常感谢。

【问题讨论】:

    标签: android opencv ocr tess-two


    【解决方案1】:

    此示例代码取自 tesseract 的 API 示例 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)));
    }
    

    【讨论】:

    • 我一直试图了解我得到答案的格式,因为“ri.getBoundingBox - 只有一个参数(级别),如文档所示:rmtheis.github.io/tess-two/javadoc/index.html(resultIterator -> getBoundingBox). 使用 int[] box = ri.getBoundingBox(TessBaseAPI.PageIteratorLevel.RIL_WORD) - 我得到这种格式的结果: [I@bf79a99 [I@4dda15e [I@6a317e0
    • 好的。抱歉,我对 Tesseract 的 Java Wrappers 了解不多。我只在 Android 上使用过 C++ 接口。如果你尝试 TessBaseAPI.PageIteratorLevel.RIL_SYMBOL 作为关卡,理论上你应该得到字符坐标
    猜你喜欢
    • 2018-10-16
    • 2018-05-12
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2020-02-04
    • 2011-03-25
    相关资源
    最近更新 更多