Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting colored lines #5

Open
i-make-robots opened this issue Nov 17, 2019 · 1 comment
Open

Sorting colored lines #5

i-make-robots opened this issue Nov 17, 2019 · 1 comment

Comments

@i-make-robots
Copy link
Collaborator

The greyscale version looks for the sequence of black lines stacked on top of a white background that will most closely approximate the original image. The color version separate the image into channels and repeats this for each channel.

For example, suppose I have black AND white lines on a grey background.

When the lines are to be combined in the finished image, I want to add line A to stack B.
Some white might be on top of some black and vice versa. Note that it might not be strictly white-black-white-black-etc.
Lines are not woven together - a new white string cannot be under previous white strings.
It is a convenient property that two lines only cross at a single point.

The test "is line A better on top of topmost-B?" is pretty quick to calculate... but wrong.
Sometimes the answer is indeterminate (lines are parallel, non-intersecting, or equal better-ness).
Sometimes it would be better to put A under some B lines, because the total error is lower than A being above all B. eg, some error might be permissible. How much? I don't know. Aye, that's the rub.

@Atanaelslompo
Copy link

imagem de tons de cinza para RGB
Mat rgbImage = new Mat();
Imgproc.cvtColor(grayImage, rgbImage, Imgproc.COLOR_GRAY2RGB);

    // Desenha as linhas na imagem original
    for (int i = 0; i < lines.rows(); i++) {
        double rho = lines.get(i, 0)[0];
        double theta = lines.get(i, 0)[1];
        double a = Math.cos(theta);
        double b = Math.sin(theta);
        double x0 = a * rho;
        double y0 = b * rho;
        Point pt1 = new Point(Math.round(x0 + 1000*(-b)), Math.round(y0 + 1000*a));
        Point pt2 = new Point(Math.round(x0 - 1000*(-b)), Math.round(y0 - 1000*a));
        Imgproc.line(rgbImage, pt1, pt2, new Scalar(0, 0, 255), 3);
    }

    // Mostra a imagem com as linhas detectadas
    Imgcodecs.imwrite("path/to/output/image.jpg", rgbImage);

}

}


This is a simple example of image processing using the OpenCV library in Java. The code loads an image, converts it to grayscale, segments it using thresholding, detects lines using the Hough transform, converts the grayscale image to RGB, draws the detected lines on the original image, and saves the output image to a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants