4

I'm using OpenCV within an iOS application. I'd like to perform OCR on some text, but I first need to determine its orientation.

How do I do that in OpenCV?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Mustafa Ibrahim
  • 1,110
  • 1
  • 9
  • 17

4 Answers4

8

I am not sure that one can reply to the question without providing OCR in Objective-C - something that can hardly be done in a few lines of text without using an OCR library.

Well, 20 years ago, I wrote an OCR system (without using any OCR library) to read bank checks in real-time. It was also authentifying hand-written signatures by the way.

The problem of checking the orientation was pregnant because checks could be inserted randomly (by human operators) in the small motorized bank-check scanner.

Since all banks were using different page layouts and decorations, the only way to find the orientation without relying on magnetic ink (that the scanner did not detect) was to actually attempt an OCR recognition on the first characters found at the top of the 'page'.

Some charcters are ambiguous like an 'O' but most others will tell you if the picture is inverted or mirrored so just reading the first 3-5 charcters will do the job (unless you have repetitions).

Good luck!

Gil
  • 3,279
  • 1
  • 15
  • 25
5

This answer was updated.

  • If you need to detect the rotation angle of the text, take a look at this article (it shares source code):

  • After the text has been deskewed, the OCR procedure can be executed and it's result compared to a dictionary. If the matching rate is high, you know the text was rotated properly and the orientation is now OK.
karlphillip
  • 92,053
  • 36
  • 243
  • 426
1

i ran into a similar problem a few weeks ago and only just started looking into it before i got distracted. Anyway, you can achieve what you want (to a degree) using discrete fourier transforms. Blur or erode the image so that all the little white gaps in the individual words/lines fill into a solid black line (this helps remove alot of the high frequency noise from the image), take the DFT of the image, apply a low-pass or band-pass filter over it (frequency according to the desired font size relative to the image size), and analyze the resulting magnitude plot. You will have to a bit of research or someone else will need to elaborate, but this definitely seemed like the best solution that i found.

Im doing another project right now, but i will get back to this within a week or so and let you know more details about it then if someone else hasnt already done so. Ofcourse, this post is kinda old now, so i may not even get a response haha, but it will be a good reference for someone else looking in the future anyway.

1

Hough transform might help you. The maximum (to be precise it's the dominant cluster, but you'll need k-means with k=1 for this) on hough voting map will give you the desired angle.

enter image description here

LovaBill
  • 5,107
  • 1
  • 24
  • 32