Largest four line segments of polygon

191 Views Asked by At

I have some polygon (see darkblue contour):

enter image description here

It consists of very small segments, pixel by pixel, so angles differ although they seem to be the same. Visually we see 4 large line segments.

How can I calculate those 4 largest line segments of polygon?

I tried to use the Douglas-Peucker algorithm (red polygon) but it gave me incorrect results:

enter image description here

I would like that the sides of the red polygon equal the sides of the card, basically this is what the expected result must look like (yellow polygon):

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

As @lhf suggested in the comments I tried Hough transform on the actual contour. This gave me a number of lines per side.

Altough I tried a wide range of parameters, Hough transform was not able to fill the gaps:

enter image description here

I solved this by dividing the lines into groups of similar lines. The weighted average of each group gave me a pretty accurate side of the card!

I have defined similar by two conditions:

  • Both lines must have (almost) the same direction.
  • The center points of both lines form a new line. This line must have almost the same direction as the others.
1
On

Douglas-Peucker does its best to find the corners, but it can't as they are rounded. Anyway, you now have a very good approximation of the quadrilateral.

What you can do is start from the corners that DP found, and on the original outline skip the segments that form the circular arc (you can simply skip on a certain length or detect curvature). Only straight edges will remain and you can extend them to their intersection.

enter image description here