De-skew characters in binary image

There are ways to deal with this. Some on the matching part to avoid the unskew operation itself like this:

But you want to unskew so:

  1. detect the rotation angle/skew slope

    Obtain bounding box, then cast vertical scan lines and remember first hit point and last regress line through all of them

    algo overview

  2. rotate/skew back by it

    So either use atan2 to obtain the angle or directly construct 2D homogenous 3×3 transform matrix based on basis vectors (one is the line and second is its perpendicular vector). For more info see:

  3. Now the rotated/unskew image will be still skewed bud in much much lower rate

    so you can apply #1,#2 in the horizontal axis too but this time you need to unskew only (do not use rotation). Usually the remnant skew ratio is small so this step is not necessary.

[notes]

You can boost the precision by filtering out wrong points or by carefully selecting the start point of scan lines so they hit in the right place of characters (you obviously know the characters count).

[edit1] small example

Here small example of output for your image (Negative as my functions are expecting white paper and black font):

example

As you can see the rotation and skew is much much smaller.

Leave a Comment