2013-07-04 57 views
0

我使用cv2.findContours來查找對象並在處理後我想保存某些輪廓。我必須先創建空圖像,然後使用cv2.drawContours命令。然而,對於這個命令文檔字符串如下:將輪廓保存爲圖像

drawContours(image, contours, contourIdx, color[, thickness[,lineType[, hierarchy[, maxLevel[, offset]]]]]) -> None 

contourIdx是必需的,雖然我不知道什麼是它應該是。

有誰知道如何獲得這個參數,或者甚至演示其他方式的轉儲輪廓文件?


更新

傾倒單輪廓contourIdx參數應設置爲-1

回答

0

這應該工作。

drawing = np.zeros(img.shape) 
for i in xrange(len(contours)): 
    if (cv2.contourArea(contours[i]) > 15000): # just a condition 
     cv2.drawContours(drawing, contours, i, (255, 255, 255), 1, 8, hierarchy) 
+0

我已經用解決方案更新了我的問題,但我會在繪製所有輪廓的全局案例中將您的答案標記爲正確。 – theta