python 下面的轮廓填充

来源:互联网 发布:网络在线棋牌 编辑:程序博客网 时间:2024/06/04 21:53

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

程序如下

import cv2import cv2.cv as cvfor 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)

0 0
原创粉丝点击