Detect text orientation

前端 未结 4 850
执笔经年
执笔经年 2020-12-14 11:57

How to detect text orientation in an image?

It doen\'t matter if the orientation is upside down (180 deg).. But if the text lines is vertical (90 or 270 deg) I need

4条回答
  •  生来不讨喜
    2020-12-14 12:42

    You can use the Hough Transform to detect the longest lines in your image and then find the predominant slope of those lines. If the slope is close to zero, your text is horizontal; if it's close to infinity, your text is vertical.

    You don't mention if you're using a library to do this, but in OpenCV you could use HoughLinesP. I used this tutorial on an image found on wikimedia:

    horizontal text

    to get this image:

    horizontal output

    Then I rotated the original image:

    vertical text

    to get this:

    enter image description here

    Since you're only interested in horizontal or vertical, you can just test whether the difference in the x-coordinates of the line endpoints is close to zero (vertical) or the difference in the y-coordinates is close to zero (horizontal).

提交回复
热议问题