使用openCV在Android中进行Hough线检测

时间:2015-12-03 13:51:46

标签: android opencv image-processing hough-transform

我的mRgba对象的尺寸为0X0,因此它不会返回图片上的任何线条  在所有。我猜它是空的。代码中有什么问题?有没有办法显示线条 黑色背景?

这是代码

    mat = new Mat();
    edges = new Mat();      
    Mat mRgba = new Mat(612,816, CvType.CV_8UC1);
    Mat lines = new Mat();

    Utils.bitmapToMat(bitmap, mat);

    Imgproc.Canny(mat, edges, 50, 90);


    int threshold = 50;
    int minLineSize = 20;
    int lineGap = 20;

    Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180,threshold,minLineSize,lineGap);



    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(mRgba, start, end, new Scalar(255, 0, 0), 3);

    }

    Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);

    Utils.matToBitmap(mRgba, bmp);
        bitmap=bmp;

编辑:通过删除GaussianBlur和阈值方法

解决了这个问题
browser-sync start --server --files "*.html, css/*.css"

1 个答案:

答案 0 :(得分:2)

  1. 您在创建mRgba时没有指定大小,它应该与您尝试查找行的图像具有相同的大小。
  2. 您应该检查lines对象,看看您是否能够找到行或 不。您可以通过查看mRgba
  3. 来了解它
  4. 这似乎不是整个代码,这里没有图像加载。您可能更好地分享整个代码和示例图像。