0

So basically, I'm creating an android app (using tesseract and OpenCV) which when given a word after pre-processing and scan steps, draws a rectangle around that word - basically "finds" the word and marks it. However I'm wondering how to get coordinates of a character ? or atleast a word ? I have coordinates of each line, but the coordinates are not relative to the "main-picture", but only coordinates of "text-blocks" that I have. Maybe someone has/knows either explanation/tutorial or some kind of info on how to go about finding coordinates of a word/character. Would highly appreciate.

1 Answers1

2

This sample code, taken from the API Examples Wiki page from tesseract should help: APIExamples

Focus on those 2 lines: 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)));
}
  • I've been trying to understand in what format I'm getting the answer, because "ri.getBoundingBox - has only one parameter (level) as shown in documentation: https://rmtheis.github.io/tess-two/javadoc/index.html (resultIterator -> getBoundingBox). after using the int[] box = ri.getBoundingBox(TessBaseAPI.PageIteratorLevel.RIL_WORD) - I get results in this kind of format: [I@bf79a99 [I@4dda15e [I@6a317e0 – Yahooo C9Wuxii May 22 '18 at 21:27
  • Ok. I'm sorry I don't know a lot about this Java Wrappers for Tesseract. I only ever used the C++ interface on Android. If you try TessBaseAPI.PageIteratorLevel.RIL_SYMBOL as level you should theoretically get character coordinates – Daniel Albertini May 23 '18 at 05:50