使用霍夫线进行线检测转换openCV android

时间:2015-02-17 22:20:51

标签: android opencv hough-transform

我正在尝试使用霍夫变换来检测图像中矩形的四个边缘。但是,结果不是我的预期:

Image

正如您所看到的,它在叶子上的某处检测到一条线而不是四条边。

Mat binary_image = new Mat();

Imgproc.threshold(gray_img, binary_image, 80, 255,   Imgproc.THRESH_BINARY_INV);

//line detection
Mat lines = new Mat();
Imgproc.HoughLinesP( binary_image, lines, 1, Math.PI/180, 80, 5, 5 );

for (int x = 0; x < lines.cols(); x++)
    {
        double[] vec = lines.get(0, x);
        double x1 = vec[0],
                y1 = vec[1],
                x2 = vec[2],
                y2 = vec[3];
        Point start = new Point(x1, y1);
        Point end = new Point(x2, y2);

        Core.line(mask, start, end, new Scalar(255,0,0), 1);

    }

任何人都可以告诉我该怎么做才能使它正确吗?

0 个答案:

没有答案
相关问题