OpenCV for Unity - HoughLines不返回任何行

时间:2016-02-03 20:55:37

标签: java c# opencv unity3d

我目前正在使用OpenCV用于Unity3d(带有C#包装器的OpenCV for Java)。我试图使用HoughLines来获取线条,但它总是空的。

Mat originalToPlaywith = Room.OriginalRGB;
Mat dst = new Mat();
Mat cdst = new Mat();

Imgproc.Canny(originalToPlaywith, dst, 50.0, 200);
Imgproc.cvtColor(dst, cdst, Imgproc.COLOR_GRAY2BGRA);

Mat lines = new Mat();
Imgproc.HoughLines(dst, lines, Mathf.PI / 180, 150, 0);

Debug.Log(lines.rows());

double[] data;
double rho;
double theta;
Point pt1 = new Point();
Point pt2 = new Point();
double a;
double b;
double x0;
double y0;

for(int i = 0; i < lines.cols(); i++)
{
    data = lines.get(0, i);
    rho = data[0];
    theta = data[1];
    a = Math.Cos(theta);
    b = Math.Sin(theta);
    x0 = a * rho;
    y0 = b * rho;
    pt1.x = Math.Round(x0 + 1000 * (-b));
    pt1.y = Math.Round(y0 + 1000 * a);
    pt2.x = Math.Round(x0 - 1000 * (-b));
    pt2.y = Math.Round(y0 - 1000 * a);
    Scalar color = new Scalar(10, 10, 10, 10);
    Core.line(dst, pt1, pt2, color, 3);
    Debug.LogWarning("Line");
}

不允许我发布图片,所以包含链接。

原始图片Unaltered Image

Canny Image Canny Image

非常感谢任何帮助。

0 个答案:

没有答案