Ask Your Question

CapAlvez's profile - activity

2018-03-14 09:18:58 -0500 received badge  Notable Question (source)
2015-08-30 12:41:31 -0500 received badge  Popular Question (source)
2012-11-14 12:39:35 -0500 asked a question opencv python - recognizing and identify coins

hey everyone. I'm trying to write a program that recognizes and identifies coins. The first thing that I did was doing the threshold of the image and then draw the contours of the objects in the image using the minimum enclosing circle. The problem is that when the coins are close to each other it recognizes by one single object and draws only one contour like this:

image description

I know I must use the cv2.getStruturingElement and cv2.erode and cv2.dilate.. but I don't understand how to use it..

Heres a part of my code:

#finds the contours of the objects 
contours, hierarchy =cv2.findContours(thresholdImage,cv2.cv.CV_RETR_CCOMP,cv2.cv.CV_CHAIN_APPROX_SIMPLE)

#draws the contours 
for i in range(len(contours)):
    if cv2.contourArea(contours[i]) > 100.0: #if the area of the object is below 100 it doesnt draw the contour
        (x,y),radius = cv2.minEnclosingCircle(contours[i])
        center = (int(x),int(y))
        radius = int(radius)
        cv2.circle(originalImage,center,radius,(0,0,255),3)

cv2.imshow('cont_2',originalImage)
cv2.waitKey(0)