I'm trying to extract the corners of a square in an image, I've managed to extract all the pixels around the square as x,y coordinates. Problem is now that I need to filter those down to only 4 corners I'm not sure what the best approach would be.
My first thought was to get the angles between each point and if the angle differs more than, say, 45 degrees it would mark a corner. Problem with this would be that since I'm working with pixels every other pixel would probably have a angle diff of more than 45 degrees.
Take this ASCII example of a corner of the square:
0000011111111111
0000011111111111
0000011111111111
00000X11X1111111
0000000011111111
0000000011111111
00000000X1111111
0000000000000000
0000000000000000
The X:s in there would all be considered a corner when what I'd really like is the part of the square to be considered only one corner, not 3.
Or this ASCII example of a part of a "slightly rotated" square with some errors in the pixels:
0011111111111
0001111111111
0000111111111
0000011111111
0000000011111 <-- A "missing pixel error"; using the ">45-degrees-diff"-method this would be a corner, right?
0000000011111
0000000001111
I'm sure there's some cool (much better) algorithms to find these so I'd love to hear your ideas on how to accomplish this sort of filtering. Or maybe there's better ways in finding the corners of a square in an image without extracting the points around it?
Edit: I forgot to clearify that the "square" in the image might be rotated, tilted and/or in a perspective.