Given the code below, the cv2.dilate and cv2.erode functions in python return the same image I send to it. What am I doing wrong? I am using OpenCV3.0.0. and numpy1.9.0 on iPython 2.7
im = np.zeros((100,100), dtype=np.uint8)
im[50:,50:] = 255
dilated = cv2.dilate(im, (11,11))
print np.array_equal(im, dilated)
Which returns:
True
{Edited} The other dilate post represents a question of kernel datatype. This post actually reflects a function call error.
The function requires a kernel, not a kernel size. So a correct function call would be below.
dilated = cv2.dilate(im, np.ones((11, 11)))
You need to specify a proper kernel. It can be rectangular, circular, etc.
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5))
im = np.zeros((100,100), dtype=np.uint8)
im[50:,50:] = 255
dilated = cv2.dilate(im, kernel, iterations = 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With