python – 填充OpenCV轮廓的外部
发布时间:2020-12-15 08:43:58 所属栏目: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
我试图用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_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) (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- `with canvas:`(Python`with something()as x:`)如何隐式
- 如何绑定tkinter中的退格键以删除多个字符?
- python – 为什么cv2扩展实际上不会影响我的图像?
- python – 寻找表达深度的递归
- python芹菜max-tasks-per-child-setting默认值
- Python:“subprocess.Popen”检查成功和错误
- python – 如何检测当前关注的应用程序?
- 如何执行python命令行自动完成,但不仅仅是在字符串的开头
- 我怎样才能在python中播放闹钟声?
- python exceptions.UnicodeDecodeError:’ascii’编解码器