3

My mRgba object has dimensions 0X0 so it doesn't return any lines on the picture at all.I guess it is empty. What is the problem in the code? Is there a way to show lines just on the black background?

Here is the code

    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;

EDIT: The problem has been solved by removing GaussianBlur and threshold methods

    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;

1 Answer 1

2
  1. You are not specifying a size for mRgba when you are creating it, it should has the same size with the image that you are trying to find lines.
  2. You should check lines object, to see if you are able to find lines or not. You can understand it by checking mRgba.
  3. This doesn't seem to be the whole code, there is no image loading here. It might be better for you to share whole code and an example image as well.
Sign up to request clarification or add additional context in comments.

15 Comments

here Utils.bitmapToMat(bitmap, mat); I'm loading an image from camera and it is absolutely fine and visible during debugging. How do I set size of a Mat object?
@marti6addams I didn't say that there is a problem about loading image, I said it is missing here. For your question, please read some documentation. Here: docs.opencv.org/2.4.11/modules/core/doc/…
@marti6addams and you can understand if you are finding the lines or not as I sad in point 2, without visualization, but still visualization is always nice.
@marti6addams Show gauss, edges, and image_binary also. And please update the code with the latest changes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.