I know this is an old question, but I had similar problems, and I found this problem through Google.
As far as I know, cv2.erode () does not change the original image, instead it returns a new image with the change applied.
changing your line containing the erode call to:
b = cv2.erode(b,element)
should see changes when you call cv2.imshow (..., b)
source share