I have written algorithm to extract the points shown in the image. They form convex shape and I know order of them. How do I extract corners (top 3 and bottom 3) from such points? I'm using opencv.
2 Answers
if you already have the convex hull of the object, and that hull includes the corner points, then all you need to to do is simplify the hull until it only has 6 points.
There are many ways to simplify polygons, for example you could just use this simple algorithm used in this answer: How to find corner coordinates of a rectangle in an image
do
for each point P on the convex hull:
measure its distance to the line AB _
between the point A before P and the point B after P,
remove the point with the smallest distance
repeat until 6 points left
If you do not know the exact number of points, then you could remove points until the minimum distance rises above a certain threshold
you could also do Ramer-Douglas-Peucker to simplify the polygon, openCV already has that implemented in cv::approxPolyDP.
Just modify the openCV squares sample to use 6 points instead of 4
-
Great! I tried your proposed solution and it worked perfectly! I'll also have a look into Ramer algorithm. – Marius Grigaitis Apr 21 '12 at 21:48
-
The Ramer-Douglas-Peucker algorithm has many uses. Glad that HugoRune suggested it. If you tinker with it, be sure to example the effect of setting different values of epsilon. Another option to finding nice squarish corners or irregular corners is to calculate the ratio of the distance between two points along a contour and the distance between those two points through the figure. For points on a straight line the ratio is 1:1. – Rethunk Apr 29 '12 at 22:46
Instead of trying to directly determine which of your feature points correspond to corners, how about applying an corner detection algorithm on the entire image then looking for which of your feature points appear close to peaks in the corner detector?
I'd suggest starting with a Harris corner detector. The OpenCV implementation is cv::cornerHarris.
Essentially, the Harris algorithm applies both a horizontal and a vertical Sobel filter to the image (or some other approximation of the partial derivatives of the image in the x and y directions).
It then constructs a 2 by 2 structure matrix at each image pixel, looks at the eigenvalues of that matrix, and calls points corners if both eigenvalues are above some threshold.

- 5,343
- 3
- 23
- 36
-
Problem is that I don't get harris to detect corners on corners. Here is what I get: http://i.imgur.com/mqltv.png – Marius Grigaitis Apr 21 '12 at 18:40