LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find the 4 points of the rectangle in multipoint

Hi all, I'm having a difficult problem I need help,

i am trying to find 4 corner points of a rectangle, is there any algorithm that can quickly find 4 corners (the result doesn't need to be very precise) ?
thanks everyone

Vu_Anh_0-1655795865605.png

 

0 Kudos
Message 1 of 4
(1,414 Views)

It's not very precise because corners are rounded and i don't know if it works for every rectangle, but you could find them by simply using Array subset function with indexes from min/max functions wired to index input of the array subset, with the length of 1.

 

This would probably not work if the rectangle was not tilted, due to noisy data (which i presume is intentional)

0 Kudos
Message 2 of 4
(1,395 Views)

I had a similar problem too that I solved by looking at the contours. Does this look good enough:

rowdyr_0-1655901604122.png

It's actually a bit tricky as you say and I don't think I found the optimal method but it does generally work okay. I'd be interested to see what others suggest because I think there must be a better way.

 

Basically I found the angles of all the line segments of the perimeter, wrapped these angles between 0 and 90 (for finding a square) then found the median angle which tells you the overall rotation of the object. Let's say the median angle was 5 degrees. I would then search the contour for four contour segments closest to 5deg, 95deg, 185 deg and 275deg. Once these segments of the contour are found the corner intersection points can be calculated through the intersection of lines. I had to cut out about 39 out of every 40 of your data points because the contour segment was only 1 pixel long and didn't give good angle readings for each segment.

 

Do you have the Vision module installed? I can post the code but it does use some Vision VIs - just simple geometric VIs you could duplicate yourself.

0 Kudos
Message 3 of 4
(1,351 Views)

I would do it like this:

Spoiler
four.png

 

0 Kudos
Message 4 of 4
(1,338 Views)