您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 填充OpenCV轮廓的外部

5b51 2022/1/14 8:22:54 python 字数 1288 阅读 659 来源 www.jb51.cc/python

我试图用openCV和 python语言在轮廓的外部区域用黑色着色. 这是我的代码: contours, hierarchy = cv2.findContours(copy.deepcopy(img_copy),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(c) for c in contours] max_inde

概述

contours,hierarchy = cv2.findContours(copy.deepcopy(img_copy),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
areas = [cv2.contourArea(c) for c in contours]
max_index = np.argmax(areas)
cnt=contours[max_index]
# how to fill of black the outside of the contours cnt please? `
import cv2
import numpy
img = cv2.imread("zebra.jpg")
stencil = numpy.zeros(img.shape).astype(img.dtype)
contours = [numpy.array([[100,180],[200,280],180]]),numpy.array([[280,70],[12,20],[80,150]])]
color = [255,255,255]
cv2.fillPoly(stencil,contours,color)
result = cv2.bitwise_and(img,stencil)
cv2.imwrite("result.jpg",result)


总结

以上是编程之家为你收集整理的python – 填充OpenCV轮廓的外部全部内容,希望文章能够帮你解决python – 填充OpenCV轮廓的外部所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶