Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

here's a python example

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