For me, the curvature:
%7D%7Bdt%5E2%7D%5Cfrac%7Bdx(t))%7D%7Bdt%7D-%5Cfrac%7Bd%5E2x(t)%7D%7Bdt%5E2%7D%5Cfrac%7Bdy(t)%7D%7Bdt%7D&space;%5Cright&space;)%5E2&space;%7D%7B&space;%5Cleft(&space;%5Cfrac%7Bd%5E2x(t)%7D%7Bdt%5E2%7D+%5Cfrac%7Bd%5E2y(t)%7D%7Bdt%5E2%7D&space;%5Cright&space;)%5E%7B3%7D&space;%7D&space;%7D)
where t is the position inside the contour and x(t) respectively. y(t) return the associated x resp. y . See here .
So, according to my definition of curvature, this can be implemented like this:
std::vector< float > vecCurvature( vecContourPoints.size() ); cv::Point2f posOld, posOlder; cv::Point2f f1stDerivative, f2ndDerivative; for (size_t i = 0; i < vecContourPoints.size(); i++ ) { const cv::Point2f& pos = vecContourPoints[i]; if ( i == 0 ){ posOld = posOlder = pos; } f1stDerivative.x = pos.x - posOld.x; f1stDerivative.y = pos.y - posOld.y; f2ndDerivative.x = - pos.x + 2.0f * posOld.x - posOlder.x; f2ndDerivative.y = - pos.y + 2.0f * posOld.y - posOlder.y; float curvature2D = 0.0f; if ( std::abs(f2ndDerivative.x) > 10e-4 && std::abs(f2ndDerivative.y) > 10e-4 ) { curvature2D = sqrt( std::abs( pow( f2ndDerivative.y*f1stDerivative.x - f2ndDerivative.x*f1stDerivative.y, 2.0f ) / pow( f2ndDerivative.x + f2ndDerivative.y, 3.0 ) ) ); } vecCurvature[i] = curvature2D; posOlder = posOld; posOld = pos; }
He works on unclosed lists. For closed loops, you can change the behavior of the border (for the first iterations).
UPDATE:
Explanation for derivatives:
The derivative for the continuous one-dimensional function f(t) :
=%5Clim%5Climits_%7Bn&space;%5Crightarrow&space;0%7D%7B%5Cfrac%7Bf(t+n)-f(t))%7D%7Bt+n-x%7D%7D&space;=&space;%5Clim%5Climits_%7Bn&space;%5Crightarrow&space;0%7D%7B%5Cfrac%7Bf(t+n)-f(t))%7D%7Bn%7D%7D)
But we are in a discrete space and have two discrete functions f_x(t) and f_y(t) , where the smallest step for t is one.

The second derivative is derived from the first derivative:

Using the approximation of the first derivative, it gives:

There are other approximations for derivatives, if you find them on Google, you will find many.
Gombat
source share