Ask Your Question
1

Deslant handwriting samples

asked 2016-04-06 00:57:33 -0600

sreyan32 gravatar image

Hello I am trying to do preprocessing on the IAM DB offline samples. Namely I want to do slant correction on each handwriting image sample they have. This is because I want to use a neural net to do handwriting recognition.

Firstly is there a way to do this in OpenCV out of the box ? Like is there a class or function that I can call something like the following ?

slant_correct(image)

If not can someone outline the steps in detail, since I am new to OpenCV.

BTW, slant correction refers to shearing the image so that handwriting samples are not slanted to the right.

An example would be following-: slant_correction.png

The problem is that every sample has different slant corrections required ie. different levels of shearing required, so how do I firstly detect the slant required and secondly how do I correct it ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2016-04-06 01:36:12 -0600

berak gravatar image

updated 2016-04-07 02:04:38 -0600

here's a python example

and it's c++ counterpart:

Mat deskew(const Mat &src)
{
    Moments m = moments(src);
    if (abs(m.mu02) < 1e-2)
        return src;
    float skew = float(m.mu11 / m.mu02);

    int SZ = src.rows; // assumes quadratic shape
    Mat_<float> M(2,3);
    M << 1, skew, (-0.5f * SZ * skew), 0, 1, 0;

    Mat dst;
    warpAffine(src, dst, M, src.size(), WARP_INVERSE_MAP | INTER_LINEAR);
    return dst;
}

image description image description

edit flag offensive delete link more

Comments

@berak. Thanks for the answer I was looking for slant correction not skew correction. I have already done skew correction in openCV following this tutorial.

sreyan32 gravatar imagesreyan32 ( 2016-04-12 06:35:21 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-04-06 00:57:33 -0600

Seen: 2,397 times

Last updated: Apr 07 '16