Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv in python: Is there a easy way to compute the curvature of a contour?

I know that you can easily compute the center of mass, and area of a contour using the moment of the contours. Is there a quick way to compute the curvature of a contour with opencv in python?

Thanks

like image 394
wudanao Avatar asked Oct 16 '25 11:10

wudanao


1 Answers

In OpenCV,

a contour is a Numpy array of (x,y) coordinates of boundary points of the object.

A method for computing the curvature is described for example in:

Driscoll MK, McCann C, Kopace R, Homan T, Fourkas JT, et al. (2012) "Cell Shape Dynamics: From Waves to Migration." PLoS Comput Biol 8(3): e1002392. doi:10.1371/journal.pcbi.1002392

They have a contour composed by 400 points (they call them boundary points) and:

At each boundary point, we calculate the boundary curvature by fitting a circle to that boundary point and the two points that are 10 boundary points away from it. The magnitude of the boundary curvature is then defined as the reciprocal of the radius of that circle.

See also this video from the above paper.

I am not familiar with Python and so I cannot suggest you a function for circle interpolation; anyway in order to fit a circle to three points you can follow the formulae from (25) to (34) from Weisstein, Eric W. "Circle." From MathWorld--A Wolfram Web Resource.

Taken from https://math.stackexchange.com/a/1215914/10799

like image 93
Alessandro Jacopson Avatar answered Oct 18 '25 05:10

Alessandro Jacopson