I’m getting this problem:

I’m using Python and OpenCV.
I’m trying to separate the contours of the touching coins using erode.
I thresholded the image and then tried to apply the erode but nothing happened. I’ve read the documentation and still don’t understand very well how the getStruturingElement and erode works.
-
I’ve thresholded the image.
-
used erode on the thresholded image.
and still nothing. What am I using wrong here?
Here’s part of the code:
import cv2, numpy as np
#1.Reads Image
objectImage = cv2.imread('P1000713s.jpg')
#2.Converts to Gray level
cvtcolorImage = cv2.cvtColor(objectImage,cv2.COLOR_RGB2GRAY)
#3.Thresholds
imgSplit = cv2.split(objectImage)
flag,b = cv2.threshold(imgSplit[2],0,255,cv2.THRESH_OTSU)
#4.Erodes the Thresholded Image
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
cv2.erode(b,element)
cv2.imshow('Eroded',b)
Looking at your image, it’s possible that a 3×3 cross mask will always stay within the thresholded area. Rather than using MORPH_CROSS, use MORPH_ELLIPSE.
If the coins are still “touching” after one call, you could always run multiple calls to erode, but be warned that this will have a destructive effect on your image.