0

I've started using OpenCV few days back, My aim is to detect a circle and its centre, I've used hough transform, I'm using a webcam of resolution 640x480,
It is working but the circle keeps on changing its position, to better explain it I posted a screen grab on youtube https://www.youtube.com/watch?v=6EGePHkGrok
Here is the code http://pastebin.com/zRG4Yfzy ,yes I know its a bit messy.
First the full video is shown, when the camera stabilizes I press ESC, then the processing begins on the ROI 250x250.
I've added few trackbars to change to parameters of hough transform and amount of blur, changing the blur amount doesn't solve the problem
How to stabilize the circle? Also the camera will not move so no tracking is needed. Or should I adopt a completely new method of doing this?
According to my understanding I need to apply some sort of filter.
The object has many circular contours, but all have the same centre, so any of the circular contour is detected its fine.

PS:I'm no Image Processing expert, I patched up the code from various sites and books

Hemal Chevli
  • 111
  • 6

1 Answers1

1

Hough transforms are known to be error prone.

For your case, you may find contours in your image and filter them by their circularity.

1- grayscale

2- low pass filter (gaussian blur)

3- canny edge detection

4- find contours and list their areas.

5- draw min enclosing circles to your contours.

6- select the contour which has min enclosing circle area closest to contour area.

7- find center of mass of the contour using moments F3 type "mass centers"

baci
  • 2,528
  • 15
  • 28
  • Wow.. thanks its working much better than hough circle, here is the result https://www.youtube.com/watch?v=jYx-snPt3aI , it needs some tweaking though.. thank you :) – Hemal Chevli Jun 25 '13 at 11:58
  • Np, and as an improvement, you may want to use [blobdetector class](http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html#simpleblobdetector) of opencv; instead of steps 3-7 :) I recently worked with this class, it is somehow faster than brute force attempts, and you can apply several kinds of filtering. – baci Jun 25 '13 at 13:53
  • I just watched the test. OK, as I see here, contours you are getting are not "circular" enough. Thats because your pre-processing steps (1-2-3) may not be the best. Try to obtain a good looking contour after canny. For your case I recommend you to apply binary thresold before canny. You will get a big square contour inside your contour list. Select the largest contour and directly find its center, ignoring steps 4-5-6. Because as I just noticed, its the central point thats important for you. – baci Jun 25 '13 at 18:52
  • Sure, I'll try both methods, also can you point me to a tutorial or sample code on simpleblobdetector class. – Hemal Chevli Jun 26 '13 at 04:46
  • [here](http://stackoverflow.com/questions/8076889/tutorial-on-opencv-simpleblobdetector) it is. – baci Jun 26 '13 at 05:05