繁体   English   中英

将轮廓保存到图像

[英]Save contour to image

我使用cv2.findContours查找对象,经过处理后,我想保存某些轮廓。 我必须先创建一个空图像,然后使用cv2.drawContours命令。 但是,此命令的文档字符串如下:

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

contourIdx是必需的,而我不知道它应该是什么。

有谁知道如何获取此参数,甚至演示将轮廓转储到文件的其他方法?


更新

用于转储单个轮廓的轮廓contourIdx参数应设置为-1

这应该工作。

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM