Detect text orientation

前端 未结 4 846
执笔经年
执笔经年 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:54

    A technique I've used successfully is to use the Radon Transform. You can find an example of an implementation here in python. You can also use the projection that you get to detect the line spacing. The python implementation above also shows how to do that.

    The intuitive explanation goes like this. For this we work with a grayscale image. Imagine you have a source of light, and some way of counting the number of light rays that touch a surface (a detector). Now imagine each character in a page acts as a wall that absorbs some of the light from passing through. Then if you shine light at an angle in the plane of the page, and put the detector on the other side, you can see that you will get the maximum light only when the light is shone in between the lines of the text. So the idea is to rotate that light source 180° around the page, and the angle where the detector captures the most light is the angle of your text. That's intuitively how a radon transform works.

    For the technical explanation of the radon transform, please see wikipedia or other sources.

    This technique allows you to detect very precisely the rotation of the text as a multiple of 180°, depending on how many "increments" of the 180° rotation you try. Of course, more precision (increments) also increases the processing time. For your use case, since you already know that the text is at a 90° angle, you can just try two increments of 90°, which should be quite fast.

    Then you need to use another technique to detect if it is upside down or not.

提交回复
热议问题