python 下面的轮廓填充

今天项目里面有个地方用到了轮廓填充,用python下面调用opencv 做轮廓填充要比直接用python自带的IPL图像处理插件要简单一些

程序如下

import cv2
import cv2.cv as cv
for c in contours:
         plength=cv2.arcLength(c,True)
         parea=cv2.contourArea(c)
         (x,y,w,h)=cv2.boundingRect(c)
         pointx=x+w/2
         pointy=y+h/2
         seed_point=pointx,pointy
         mask = np.zeros((200+2, 200+2), np.uint8)
         if ((plength/5)*(plength/5))>parea:
             cv2.floodFill(edgeimage,mask,seed_point,(0,0,0))
             cv2.drawContours(edgeimage,c,-1,(0,0,0))

         elif 100<parea<243:
             cv2.floodFill(edgeimage,mask,seed_point,(255,255,255))
             cv2.drawContours(edgeimage,c,-1,(255,255,255))
         elif parea<400:
             cv2.floodFill(edgeimage,mask,seed_point,(180,180,180))
             cv2.drawContours(edgeimage,c,-1,(180,180,180))
         elif parea<2000:
             cv2.floodFill(edgeimage,mask,seed_point,(100,100,100))
             cv2.drawContours(edgeimage,c,-1,(100,100,100))

edgeimage=cv2.medianBlur(edgeimage,3)
cv2.imshow("filled window",edgeimage)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值