Issue 1144 in tesseract-ocr: PageIterator::BoundingBoxInternal() sometimes gives wrong vertical coordinates

35 views
Skip to first unread message

tesser...@googlecode.com

unread,
Apr 19, 2014, 7:21:44 AM4/19/14
to tesserac...@googlegroups.com
Status: New
Owner: ----

New issue 1144 by p.vorb...@gmail.com: PageIterator::BoundingBoxInternal()
sometimes gives wrong vertical coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

PageIterator::BoundingBoxInternal() sometimes returns 0 values for top and
bottom for RIL_WORD while left and right are always correct. When the first
word with 0 values occurs, all following words in the page also have top ==
0 and bottom == 0. Repeating recognition on the same page may result in
different results.

I am using the C API via Java to get bounding box information for
recognized words. The error is not due to the C-Java-binding, I verified
that the zeros also occur from within Tesseract.

I attached a patch file that solves this issue:

The wrong values are caused by implicitly casting from inT16 to int in
PageIterator::BoundingBoxInternal() when converting the coordinates to
top-down.

For some reason calculating the left and right coordinates is done by a
static_cast<int>(box.left()) (same with right) but with top and bottom it
is not. Adding the static_cast for top and bottom solves the issue.

Attachments:
correct-box-coordinates.diff 806 bytes

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

tesser...@googlecode.com

unread,
Apr 23, 2014, 3:20:41 PM4/23/14
to tesserac...@googlegroups.com

Comment #1 on issue 1144 by p.vorb...@gmail.com:
PageIterator::BoundingBoxInternal() sometimes gives wrong vertical
coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

I just noticed that the errors I reported are not fixed by my patch. It
seems that for some other reason the coordinates were correct during my
tests after applying the patch.

tesser...@googlecode.com

unread,
Apr 24, 2014, 4:15:32 PM4/24/14
to tesserac...@googlegroups.com

Comment #2 on issue 1144 by zde...@gmail.com:
PageIterator::BoundingBoxInternal() sometimes gives wrong vertical
coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

Can you provide simple test case with (input) image, so we can have a look
on it?

tesser...@googlecode.com

unread,
May 2, 2014, 6:37:15 AM5/2/14
to tesserac...@googlegroups.com

Comment #3 on issue 1144 by p.vorb...@gmail.com:
PageIterator::BoundingBoxInternal() sometimes gives wrong vertical
coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

Sorry, it seems I didn't receive an email notification.

I attached an image that (sometimes) causes the error.

I get the errors through my own custom Java wrapper, which isn't released
yet. Today I tried to get the error through C++ code, but I couldn't.
Here's the code I used:

Pix *image = pixRead("fries_example.png");
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
api->Init(NULL, "deu-frak");
api->SetImage(image);
api->Recognize(0);
tesseract::ResultIterator* ri = api->GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_WORD;

if (ri != 0) {
do {
const char* word = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
printf("word: '%s'; BoundingBox: %d,%d,%d,%d;\n",
word, x1, y1, x2, y2);
delete[] word;
} while (ri->Next(level));
}

My Java code is basically doing the same using the C API.

Since I didn't get the error in my C++ program, it has got something to do
with the Java wrapper I am using or the way I am initializing the
recognition process. I'll look into the Java code again and let you know
when I find the problem.

Attachments:
fries_example.png 51.8 KB

tesser...@googlecode.com

unread,
May 2, 2014, 6:53:02 AM5/2/14
to tesserac...@googlegroups.com

Comment #4 on issue 1144 by p.vorb...@gmail.com:
PageIterator::BoundingBoxInternal() sometimes gives wrong vertical
coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

The error was a concurrency issue in Java. I initialized the API in one
thread and then iterated over the recognition results in another thread,
which caused the problem. I still don't know why exactly the y coordinates
(and no other) were affected, but using the same thread to initialize and
iterate gives me correct results.

This issue may be closed.

tesser...@googlecode.com

unread,
May 2, 2014, 11:26:33 AM5/2/14
to tesserac...@googlegroups.com
Updates:
Status: No-longer-an-issue

Comment #5 on issue 1144 by zde...@gmail.com:
PageIterator::BoundingBoxInternal() sometimes gives wrong vertical
coordinates
http://code.google.com/p/tesseract-ocr/issues/detail?id=1144

(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages