06-21-2022 02:26 AM
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
06-21-2022 03:09 AM - edited 06-21-2022 03:11 AM
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)
06-22-2022 08:06 AM - edited 06-22-2022 08:08 AM
I had a similar problem too that I solved by looking at the contours. Does this look good enough:
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.
06-22-2022 08:57 AM