def _smooth_ball_mask(self, mask):
"""
The mask created inDetectBallPosition might be noisy.
:param mask: The mask to smooth (Image with bit depth 1)
:return: The smoothed mask
"""
# create the disk-shaped kernel for the following image processing,
r = 3
kernel = np.ones((2*r, 2*r), np.uint8)
for x in range(0, 2*r):
for y in range(0, 2*r):
if(x - r + 0.5)**2 + (y - r + 0.5)**2 > r**2:
kernel[x, y] = 0
# remove noise
# see http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
return mask
评论列表
文章目录