Ask Your Question
0

opencv python - recognizing and identify coins

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

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,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)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

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

theluckyone gravatar image

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

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: http://opencvpython.blogspot.pt/2012/05/skeletonization-using-opencv-python.html 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

Question Tools

Stats

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

Seen: 6,099 times

Last updated: Nov 19 '12