How to prevent tesseract from rotating input image?

3,925 views
Skip to first unread message

Dan9er

unread,
Sep 30, 2017, 11:37:29 AM9/30/17
to tesseract-ocr
I'm working on a project, and my input images are all portrait. However, tessedit_write_images reveals that the images are being rotated to landscape! I think this is one of Tesseract's "hacks" that it uses for better OCR, but in my case, it's counterproductive since the text I want to OCR ends up sideways.

How do I override the auto-rotation? The only config variable I could find related to rotation is textord_test_landscape, which defaults to 0.

Dan9er

unread,
Oct 3, 2017, 8:46:13 AM10/3/17
to tesseract-ocr
Bump.

If noone can help me, can someone point me to a dev that I can PM?

Dan9er

unread,
Oct 6, 2017, 7:14:29 PM10/6/17
to tesseract-ocr
Bump

Tom Morris

unread,
Oct 7, 2017, 3:49:27 PM10/7/17
to tesseract-ocr
The only time Tesseract should rotate the image is if you're using a page segmentation mode that includes "Orientation & Script Detection (OSD)" https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage

Try a different mode.

Tom

Dan9er

unread,
Oct 8, 2017, 11:12:15 AM10/8/17
to tesseract-ocr
ALL of the page segmentation modes rotate the image according to tessedit_write_imagesTrust me, I tried (see attached image).

I made a GitHub issue here because I think the override is a unimplemented feature.
Screenshot from 2017-10-08 11-10-33.png

Dan9er

unread,
Oct 13, 2017, 12:01:20 PM10/13/17
to tesseract-ocr
Bump

Dan9er

unread,
Oct 15, 2017, 11:42:45 AM10/15/17
to tesseract-ocr
Bump

Dmitri Silaev

unread,
Oct 15, 2017, 9:47:33 PM10/15/17
to tesser...@googlegroups.com
OK, I think, it's a bunch of your fallacies. But let's start from the beginning. Send the exact image you are passing to Tess, version of Tess, your config file, and the command line.

-Dmitri





--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-ocr+unsubscribe@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/9d8afbd1-ec4a-4149-834d-d3f95a4df149%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan9er

unread,
Oct 21, 2017, 1:35:05 PM10/21/17
to tesseract-ocr
Version:
tesseract 3.05.01
 leptonica-1.74.4
  libjpeg 8d (libjpeg-turbo 1.4.2) : libpng 1.2.54 : libtiff 4.0.6 : zlib 1.2.8

Command line:
$ tesseract NPN_80051578.jpg out --psm 12 npn_writeimage
Tesseract Open Source OCR Engine v3.05.01 with Leptonica
Warning. Invalid resolution 0 dpi. Using 70 instead.
OSD: Weak margin (3.87) for 73 blob text block, but using orientation anyway: 3
Detected 16 diacritics

All files are attached. npn_writeimage is basically bazaar + digits + tessedit_write_images=1.

This is one of the cases that OCR correctly anyway. Running Tesseract with the same bottle but with a horizontal orientation shows that tessinput.tif is not rotated.
I don't think the image Tesseract processes is necessarily the same as tessinput.tif. It's always getting rotated to landscape. Maybe there is something wrong with the write_images script. Hell, maybe even Ubuntu is messing with it for all I know. ¯\_(ツ)_/¯

On Sunday, October 15, 2017 at 9:47:33 PM UTC-4, Dmitri Silaev wrote:
OK, I think, it's a bunch of your fallacies. But let's start from the beginning. Send the exact image you are passing to Tess, version of Tess, your config file, and the command line.

-Dmitri





On Sun, Oct 15, 2017 at 11:42 AM, Dan9er <dan9ert...@gmail.com> wrote:
Bump

On Friday, October 13, 2017 at 12:01:20 PM UTC-4, Dan9er wrote:
Bump

On Sunday, October 8, 2017 at 11:12:15 AM UTC-4, Dan9er wrote:
ALL of the page segmentation modes rotate the image according to tessedit_write_imagesTrust me, I tried (see attached image).

I made a GitHub issue here because I think the override is a unimplemented feature.
On Saturday, October 7, 2017 at 3:49:27 PM UTC-4, Tom Morris wrote:
The only time Tesseract should rotate the image is if you're using a page segmentation mode that includes "Orientation & Script Detection (OSD)" https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage

Try a different mode.

Tom

On Friday, October 6, 2017 at 7:14:29 PM UTC-4, Dan9er wrote:
Bump

On Tuesday, October 3, 2017 at 8:46:13 AM UTC-4, Dan9er wrote:
Bump.

If noone can help me, can someone point me to a dev that I can PM?

On Saturday, September 30, 2017 at 11:37:29 AM UTC-4, Dan9er wrote:
I'm working on a project, and my input images are all portrait. However, tessedit_write_images reveals that the images are being rotated to landscape! I think this is one of Tesseract's "hacks" that it uses for better OCR, but in my case, it's counterproductive since the text I want to OCR ends up sideways.

How do I override the auto-rotation? The only config variable I could find related to rotation is textord_test_landscape, which defaults to 0.

--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
NPN_80051578.jpg
out.txt
tessinput.tif
npn_writeimage

Dan9er

unread,
Oct 21, 2017, 1:37:23 PM10/21/17
to tesseract-ocr
Ok wow, I swear NPN_80051578.jpg was portrait when I uploaded it!

Dmitri Silaev

unread,
Oct 21, 2017, 5:12:01 PM10/21/17
to tesser...@googlegroups.com
Without delving deeper, I can suggest that you probably need to investigate your image EXIF orientation value. Most image handling libraries respect it. I suppose your image viewer also supports this parameter, but can also have settings to disregard or override it. Some unsophisticated libraries just don't support it. Not sure about Leptonica, its image buffer layout and image writer operation. Google Groups or Gmail might have their own logic for processing image attachments.

Next, as long as you can see bits of correctly recognized text, Tesseract does it all right with orientation detection.

And one more thing. Tesseract does not "physically" do image buffer rotation. Everything it does is "rotating" internal structures resulted from the binary image analysis such as blobs, segmenter settings and table finder settings. So the overhead is not so big as you think. But still OSD is not very reliable and takes some time, therefore I would make sure the input image is as good as it can be including orientation.

-Dmitri






To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-ocr+unsubscribe@googlegroups.com.

To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.

Dan9er

unread,
Oct 22, 2017, 12:50:08 PM10/22/17
to tesseract-ocr
Experimenting with exiftool, turns out the vertical image's orientation data is set to 6 (Rotate 90 CW). Setting this value to 1 (don't rotate) makes the image rotate 90 CCW, as expected.

So, I suspect that something along the chain of processes is not respecting this value. Is this a bug?

-Dmitri






Dmitri Silaev

unread,
Oct 23, 2017, 11:58:22 AM10/23/17
to tesser...@googlegroups.com
Image handling in Tesseract is done with Leptonica. I have little knowledge of it, sorry. There some Leptonica gurus in the group who probably can help.

-Dmitri



To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-ocr+unsubscribe@googlegroups.com.

To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.

Dan9er

unread,
Oct 23, 2017, 1:20:33 PM10/23/17
to tesseract-ocr
I'll go bother them about it here: https://github.com/DanBloomberg/leptonica/issues/251

Thank you so much!

-Dmitri



Tom Morris

unread,
Oct 23, 2017, 1:51:01 PM10/23/17
to tesser...@googlegroups.com
I suspect they consider it more a limitation or missing feature than a bug.

Traditional image processing has always been done in raster order and the EXIF information is considered out-of-band/ignored by packages that don't deal with consumer images.

Tom

Dmitri Silaev

unread,
Oct 23, 2017, 1:53:46 PM10/23/17
to tesser...@googlegroups.com
Hmm... That's what I thought. If I were you, I wouldn't bother myself with Leptonica at all. Just make sure the input image is as well prepared as it can be then feed it to Tesseract.

-Dmitri


To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-ocr+unsubscribe@googlegroups.com.

To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
Reply all
Reply to author
Forward
0 new messages