java, I would like to create a program that detects intersections from multiple straight lines and recognizes parts where more intersections are detected.
What i am doing nowCurrently, the captured image is Canny processed and Hough transformed,
A straight line was detected.
Below is the code.
public class HoughClass {
static {
System.loadLibrary (Core.NATIVE_LIBRARY_NAME);
}
public static void main (String [] args) {
final String path_in = "wall02.jpg";
final String path_grayout = "wall02_gray.png";
final String path_cannyout = "wall02_canny.png";
final String path_houghout = "wall02_hough.png";
final String path_houghPout = "wall02_houghP.png";
Mat src = new Mat ();// SourceMat
Mat cdst = new Mat ();// CannyDestinationMat
Mat cdstP = new Mat ();// CannyColorDestinationMat
Mat gray = new Mat ();// GrayMat
Mat canny = new Mat ();// CannyEdgeMat
Mat lines = new Mat ();// HoughlineMat
Mat linesP = new Mat ();// HoughlinePMat
src = Imgcodecs.imread (path_in);// read image
// Check Input-Image
if (src.empty ()) {
System.out.println ("Error opening image!");
System.exit (-1);
}
// ToGray
Imgproc.cvtColor (src, gray, Imgproc.COLOR_RGB2GRAY);
// Edge detection
Imgproc.Canny (gray, canny, 10, 50);
// Copy edges to the images that will display the results in BGR
Imgproc.cvtColor (canny, cdst, Imgproc.COLOR_GRAY2BGR);
cdstP = cdst.clone ();
// Standard Hough Line Transform
Imgproc.HoughLines (canny, lines, 1, Math.PI/360, 150);// runs the actual detection
// Draw the lines
for (int x = 0;x<lines.rows ();x ++) {
double rho = lines.get (x, 0) [0],
theta = lines.get (x, 0) [1];
double a = Math.cos (theta), b = Math.sin (theta);
double x0 = a * rho, 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 (cdst, pt1, pt2, new Scalar (0, 0, 255), 1, Imgproc.LINE_AA, 0);
}
// Probabilistic Line Transform
Imgproc.HoughLinesP (canny, linesP, 1, Math.PI/360, 50, 60, 10);// runs the actual detection
// Draw the lines
for (int x = 0;x<linesP.rows ();x ++) {
double [] l = linesP.get (x, 0);
Imgproc.line (cdstP, new Point (l [0], l [1]), new Point (l [2], l [3]), new Scalar (0, 0, 255), 1, Imgproc.LINE_AA, 0);
}
Imgcodecs.imwrite (path_in, src);
Imgcodecs.imwrite (path_grayout, gray);
Imgcodecs.imwrite (path_cannyout, canny);
Imgcodecs.imwrite (path_houghout, cdst);
Imgcodecs.imwrite (path_houghPout, cdstP);
}
}
Execution results
Top: Gray image, Bottom: Hough transform
Multiple lines were detected, but no intersection point has been detected.
I checked and found that there was an article that asked for the intersection of two straight lines.
What should I do for multiple straight lines?
Please professor.
-
Answer # 1
-
Answer # 2
What should I do for multiple lines?
I think it can be obtained with an array of straight lines, so I think that there is no choice but to find the intersection point for each combination.
If you write it roughly,
for (int x = 0;x
is a double loop,
for (int x = 0;x
Like
Related articles
- java - i want to set multiple items in the database, but i get an error that the number of arguments does not match
- java - i want to transfer the answers entered from multiple google forms to another psi
- how to register multiple lines at once from form registration in access
- python - how to expand list type element in multiple lines in pandas dataframe
- java - i want to input multiple times with scanner
- java - i want to use the saved values in multiple programs
- c++ - how to read multiple lines of data
- java - i want to display multiple objects whose black eye direction changes
- i want to retrieve multiple lines of average using sqlite in c#
- java - i want to sort the variables of list using multiple value values of map
- duplicate check for multiple java input fields
- java - search multiple items about how to write findby 〇 and △ like()
- java - please tell me how to handle multiple responses with retrofit2
- java: cat command to display the contents of multiple text files
- java - i want to check if multiple numbers are duplicated
- i want to do multiple types in the argument of java class
- java - how to execute multiple classes at the command prompt
- java - read/write multiple files
- java - about reading and writing multiple files
- python - output multiple lines of comma-delimited data read
- java : Russian letters are replaced by scribbles
- java - i get a message saying that i can't forward after committing the response
- java - i want to set 10 (minutes): 00 (seconds): 00 (milliseconds) to the format specified by datetimeformatter!
- java - i want to resolve null errors
- java - i don't understand the schedule management created by session management
- java - i want to use opencv to load a tensorfrow trained model and process mask rcnn
- java - i want to upload and save images with servlet and jsp
- java - to read all programs
- eclipse - update the centos8 package
- java - i want to enter the date of birth and output the date of birth and the day of the week
The approach seems to be different depending on the purpose of the process,
Imagine that it might be troublesome if multiple lines appear like the red line in the image (because it depends on the process, it seems to directly affect "weight"), so
I think it is necessary to make a judgment such as "I don't think about the intersection of these two lines because they are close to this line."
(It may be possible to devise a method that suppresses multiple occurrences from the beginning to some extent by reducing the resolution of r in the Hough space.)
... is a way to find the location where multiple lines cross, but for example ...
When the intersection of two lines is calculated in a brute force manner that others have answered, but ignoring pairs of lines that are "close to each other" [ Count the number of lines that are within the threshold and are not close to either of the two lines for which the intersection was calculated, and the result is the intersection with the largest number.
I think a method like this can be considered.