[英]Save contour to image
I used cv2.findContours
to find objects and after processing I want to save certain contour(s). 我使用
cv2.findContours
查找对象,经过处理后,我想保存某些轮廓。 I must first create empty image and then use cv2.drawContours
command. 我必须先创建一个空图像,然后使用
cv2.drawContours
命令。 However docstring for this command is following: 但是,此命令的文档字符串如下:
drawContours(image, contours, contourIdx, color[, thickness[,lineType[, hierarchy[, maxLevel[, offset]]]]]) -> None
and contourIdx
is required, while I have no idea what is it supposed to be. 和
contourIdx
是必需的,而我不知道它应该是什么。
Does anyone know how to get this parameter, or even demonstrate other way of dumping contours to file? 有谁知道如何获取此参数,甚至演示将轮廓转储到文件的其他方法?
Update : 更新 :
for dumping single contour contourIdx
parameter should be set to -1
用于转储单个轮廓的轮廓
contourIdx
参数应设置为-1
This should work. 这应该工作。
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.