2013-02-28 52 views
0

我发现这种方式来计算图像矩如何计算opencv中凸包的伸长率?

#ELONGATION 
def elongation(m): 
    x = m['mu20'] + m['mu02'] 
    y = 4 * m['mu11']**2 + (m['mu20'] - m['mu02'])**2 
    return (x + y**0.5)/(x - y**0.5) 

mom = cv2.moments(unicocnt, 1)  
elongation = elongation(mom) 

我该如何计算凸包的伸长率伸长筑底?

hull = cv2.convexHull(unicocnt) 

其中'unicocnt'是用查找轮廓拍摄的轮廓。

+0

难道你不能在船体轮廓上运行相同的功能吗? – 2013-02-28 12:24:07

回答

1

默认情况下,convexHull输出点的索引向量。您必须将returnPoints参数设置为1以输出可以传递给cv2.moments的点向量。

+0

只有船体和顺时针参数 – postgres 2013-02-28 12:51:23

+1

你使用哪个版本的OpenCV? [Here is](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=rect#convexhull)cv2.convexHull的文档,我可以看到4个参数。 – cedrou 2013-02-28 12:59:48