I am working on a project of coin identification. First thing I with that I am stuck is correct coin extraction from the image, even from very simple image. There are exists alot of good working methods for coin detection but all of them as I see need manual check after applying. I have tested two of them:
cv2.HoughCircles and threshold with findig countours after it .
Here some successfull examples of processing:
cv2.HoughCircles, good result
cv2.HoughCircles, bad result
But for the second image works great solution of threshloding and finding countours after it:
something like this:
gray = cv2.GaussianBlur(gray, (15, 15), 0)
#gray = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV, 11, 1)
(_,gray) = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for i,cnt in enumerate(contours):
ellipse = cv2.fitEllipse(cnt)
print ellipse,type(ellipse)
cv2.ellipse(color_img, ellipse, (0,255,0), 2)
produces very good result:
But for some other image it works very pure,
this has happened because coins are to close one from the other and bluring has merged them. It is very simple cas and for it i can just check if result is only one contour decline it . But sometimes it's more complicated. I want to implement some algo that tryes diferent metods of segmentation and chooses the best one. But its hard to encode for me this metric - has anybody Ideas how to do it ?
Original images from example: this 3 are rather qute , but actually is not the rule - some of them has background some of them even not coins - thats why I am thinking about some postchecking process.