【问题标题】:Hough line detection in android using openCV使用openCV在android中检测霍夫线
【发布时间】:2015-12-03 13:51:46
【问题描述】:

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

这里是代码

    mat = new Mat();
    edges = new Mat();
    Size kernel = new Size(5, 5);
    Mat gauss = new Mat();
    Mat mRgba = new Mat(612,816, CvType.CV_8UC1);
    Mat lines = new Mat(612,816, CvType.CV_8UC1);
    binary_image = new Mat();
    Utils.bitmapToMat(bitmap, mat);
    Imgproc.GaussianBlur(mat, gauss, kernel, 10000, 10000);
    Imgproc.Canny(gauss, edges, 50, 90);
    Imgproc.threshold(edges, binary_image, 0, 255, Imgproc.THRESH_BINARY_INV);

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

    Imgproc.HoughLinesP(binary_image, 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 和阈值方法解决

    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;

【问题讨论】:

    标签: android opencv image-processing hough-transform


    【解决方案1】:
    1. 您在创建mRgba 时没有指定其大小,它应该与您尝试查找线条的图像具有相同的大小。
    2. 你应该检查lines对象,看看你是否能找到行或 不是。可以查看mRgba了解。
    3. 这似乎不是完整的代码,这里没有图像加载。您最好共享整个代码和示例图像。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-09
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多