views:

260

answers:

3

I have no background in computer vision, but I was curious to know how I could use OpenCV library to achieve the following:

I have a jar of spare buttons, assorted in colour, style and diameter. For the most part they are circular. I evenly scatter them on a piece of white paper, and under good lighting, take a fairly high resolution picture with your average digital camera. How would I got about slicing this image to grab each button individually as a separate object/image?

Thanks in advance.

+2  A: 

I think the simplest thing you could try is: run the Canny edge detector and apply a Hough transform to detect circles and generate a separate image from each of the circles.

carlosdc
+1  A: 

I've been doing some dish recognition and it worked pretty good. do this:

Do some thresholding (buttons should be shiner than background) to leave only the buttons,

then cvFindContours

for each contour:

  • run cvFitEllipse, it will return you both axis (a,b) of the fitted ellipse.
  • check that the area of an ellipse PI*a*b is similar to the Area of the contour using cvContourArea and also that both axis are similar a = b. (this will leave only circles)
  • then you can do whatever you need. printContour, using cvPrintContour, use cvMinAreaRect2 to get button bounding box, etc

Hough transform is also possible but it is quite more expensive.

dnul
thanks a lot for your reply, i'll try out these methods.
Karan
+2  A: 

Two possible ways:

1) Using the circle hough transform You run some edge detector (canny/sobel) and then the circle hough transform. You'll get the circles.

2) Using contours Seperate the button and background using thresholding. Detect contours in this thresholded image and you have the buttons!

Articles that might help:

Utkarsh Sinha
thanks a lot for your reply, i'll try out these methods.
Karan