今天项目里面有个地方用到了轮廓填充,用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)