Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV to detect clothing buttons on a piece of paper

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.

like image 222
Karan Avatar asked Jul 15 '10 02:07

Karan


3 Answers

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:

  • Contours: http://aishack.in/tutorials/an-introduction-to-contours/
  • Thresholding: http://aishack.in/tutorials/thresholding/
  • Hough circles: http://aishack.in/tutorials/hough-circles-in-opencv/

Disclaimer: Those are links to my website.

like image 139
Utkarsh Sinha Avatar answered Nov 02 '22 03:11

Utkarsh Sinha


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.

like image 40
carlosdc Avatar answered Nov 02 '22 02:11

carlosdc


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 PIab 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.

like image 20
dnul Avatar answered Nov 02 '22 02:11

dnul