2013-07-04 49 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