Ask Your Question

Revision history [back]

My suggestion, calculate the angle between 3 subsequent points on your contour. If the angles start changing drastically, then you will hit an irregularity inside your contour. By limiting the range of angles you can even find concavities and convexities.

Calculating angle between points can be done as follows:

static int angle( Point a, Point b, Point c )
{
    cv::Point2d ab = { b.x - a.x, b.y - a.y };
    cv::Point2d cb = { b.x - c.x, b.y - c.y };

    float dot = (ab.x * cb.x + ab.y * cb.y); // dot product
    float cross = (ab.x * cb.y - ab.y * cb.x); // cross product

    float alpha = atan2(cross, dot);

    return abs(floor(alpha * 180. / M_PI + 0.5));
}