Wednesday, July 22, 2009

Circle Detection with OpenCV



The documentation for OpenCV is getting pretty good, I was able to get circle detection working via cut and paste pretty quickly. However, I suggest adding a cvWaitKey(0); to the end of the example code so that you can see it actually running.

Also it looks like the accumulator for the Hough transform used by cvHoughCircles() only looks for maximas along the X and Y axes of the parameter space so concentric circles will not be detected as separate circles.

Update:This series of tutorials on integrating circle detection into ROS using OpenCV may also be useful.

10 comments:

Anonymous said...

hi.. m having a problem in compiling this program.. it says "too few arguments to function cvHoughCircles and cvSmooth"

can u please explain it n hw to remove this?
u can reply by mailing at shoaibkhan06@gmail.com
Thanx in advance

I Heart Robotics said...

I would check the version of OpenCV you are using and use ldd to check that you are not having any linking errors.

Dennis said...

What if I want to get the center of the circles detected, what codes of OpenCV should I use? please reply on this e-mail address: dhenn0021@gmail.com... your opinion will be highly appreciated... thanks

I Heart Robotics said...

The documentation has how to do it.

Specifically from this code fragment

float* p = (float*)cvGetSeqElem( circles, i );
cvCircle( img,
cvPoint(cvRound(p[0]),cvRound(p[1])),
3,
CV_RGB(0,255,0),
-1, 8, 0 );

p[0] and p[1] are the x,y of the center of the circle.

Dennis said...

what if i successfully detect the ball and the center of the circle detected, how could I calculate angle of the circle detected with for example, respect to the center of the frame? thanks for reply :)

I Heart Robotics said...

The arc tangent of Y/X will give an angle. I don't know if that is the angle you need but you should be able to determine the angle you want with some trigonometry.

Dennis said...

Ok I get it... Thank you very much for reply...

Anonymous said...

Can somoeone pls give the link of the code?

Flavio said...

Where is the code?
Can anyone tell where I find this code?

I Heart Robotics said...

The code is here
https://github.com/IHeartRobotics/iheart-ros-pkg