Ask Your Question

opencv python - recognizing and identify coins

asked 2012-11-14 12:39:35 -0500

CapAlvez gravatar image

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,,

#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),center,radius,(0,0,255),3)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-11-19 15:10:46 -0500

theluckyone gravatar image

updated 2012-11-19 15:29:08 -0500

You gotta go step by step. First, you should binarize the image. Then, you use erode or dilate to enhance the picture. You should use those functions to split the coins that are together. Erode and dilate both use a structuring element, which has a shape and a size. You should check this link to see an example of usage: I also suggest you search more about the functions findcontours and drawcontours, because they will be very helpful to you.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-11-14 12:39:35 -0500

Seen: 4,872 times

Last updated: Nov 19 '12