Here I have some quads in an image, and now I want to separate them into a single quad. Here is the image of the quads
quads, and each shape like this I call a quad quad( a quad is formed by 4 points). Given that I've already had the coordinates of each line segment. For each line, I have their 2 endpoints, but I don't know which point is endpoint 1 or endpoint 2 endpoints of a line. If 2 lines are intersected, I also have their corner coordinate.
So in general, I have 3 lists:
- A list of endpoint 1 coordinates
- A list of endpoint 2 coordinates
- A list of corner coordinates if 2 lines are intersected
The range of endpoint 1's list and endpoint 2's list is the same, but different to the corner's list.
Could you give me some suggestions to separate the quads? This is the result that I want to achieve desire result
What I have tried:
I tried to get 4 coordinates for each quad:
- for i in endpoint 1:
-for j in corners: check if point 1 or point 2 close to the corner, then I have 2 points for a quad check if point 1 or 2 close to corner
-for z in endpoint 2(or endpoint 1 is okay because they have the same range): find a line through a corner and point 2 or point 1, if a corner point belongs to this line, then I will have 3rd point for the quad.
-for g in endpoint 2: check if 3rd point is close to point 1: then 4th point = point 2, otherwise = point 1.
As you can see, there are so many for loops, and it even does not work. If you have any idea or suggestion, please help
Edit: This is the input image input image