2013-02-28 29 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