def CloseInContour( mask, element ):
large = 0
result = mask
_, contours, _ = cv2.findContours(result,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#find the biggest area
c = max(contours, key = cv2.contourArea)
closing = cv2.morphologyEx(result, cv2.MORPH_CLOSE, element)
for x in range(mask.shape[0]):
for y in range(mask.shape[1]):
pt = cv2.pointPolygonTest(c, (x, y), True)
#pt = cv2.pointPolygonTest(c, (x, y), False)
if pt > 3:
result[x][y] = closing[x][y]
return result.astype(np.float32)
评论列表
文章目录