Question

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

Was it helpful?

Solution

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"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top