Auto rotate scanned text image (OCR via command line?)

8,912

I currently do this with tesseract using the switches "-psm 0" which will detect orientation of the image.

Sample output :

Tesseract Open Source OCR Engine v3.04.00 with Leptonica
Orientation: 3
Orientation in degrees: 90
Orientation confidence: 3.94
Script: 1
Script confidence: 13.81

Then I run ImageMagick to rotate the image to the correct orientation. It does work for most of the images, except for handwritten documents and photos.

A bit kludgy, but it is a lot faster than running OCR four times.

Share:
8,912

Related videos on Youtube

nixda
Author by

nixda

Updated on September 18, 2022

Comments

  • nixda
    nixda almost 2 years

    Can I auto-rotate an image that contains mainly text? Maybe via OCR? The algorithm or whatever needs to scan the image and decide if it has to rotate it 90°, 180° or 270°

    I want to include this feature into an existing PowerShell script, so command-line ability is mandatory.

    I'm open for ImageMagick solutions

    Example

    enter image description here
    Click to enlarge

    I have already read the following SO questions. But they rotate photos.
    and I'm only trying to rotate pure text scans which have no EXIF metadata.