0

i want to detect the skew level from an image. I've the following code:

public void analyse(CvMat img) {

    rows = img.rows();
    cols = img.cols();
    // create edge-map from rois
    CvMat edgeMap = cvCreateMat(rows, cols, CV_8UC1);

    cvCanny(img, edgeMap, 100, 400, 3);

    // transform to hough
    CvMemStorage storage = cvCreateMemStorage(0);
    lines = cvHoughLines2(edgeMap, storage, CV_HOUGH_PROBABILISTIC, 1,


    EuclideanDistance euclideanDistance = new EuclideanDistance();
    double maxDistance = Double.MIN_VALUE;
    for (int i = 0; i < lines.total(); ++i) {
        Pointer line = cvGetSeqElem(lines, i);
        CvPoint pt1 = new CvPoint(line).position(0);
        CvPoint pt2 = new CvPoint(line).position(1);
        double distance = euclideanDistance.getDistance(pt1, pt2);
        double currentAngle = Math.atan2(pt2.y() - pt1.y(),
                pt2.x() - pt1.x())
                * 180 / Math.PI;
        System.out.println(currentAngle);
        if (distance > maxDistance) {

            skewAngle = currentAngle;

        }
    }

My test image is skew

I think the skew level is by -16 degree but my code says, that is by 25...

The for prints out a avg angle by 25,too. Thats wrong with my hough parameters?

//EDIT here is a drawing from the houghLines enter image description here

greetings

4

1 回答 1

0

首先,既然你有一个相当清晰的文本,我建议你在 Canny 和 Hough 之前使用 dilate/erode。你会在信件中得到更多的分数,霍夫肯定会从中受益。

其次,您选择“最佳角度”作为直线两点之间的最大距离。

double distance = euclideanDistance.getDistance(pt1, pt2);
...
if (distance > maxDistance) {
    skewAngle = currentAngle;
}

这是行不通的,因为实际上 Hough 可能会检测到一条不相关的行,它比任何文本行都长:

霍夫失败

如果你向自己展示所做的每一步,你可能会得出一个更好的算法——你在 Canny 之后得到了什么,霍夫变换产生了什么线等等。

于 2012-08-31T11:55:53.700 回答