OpenCV provides and inbuilt function to detect circles in your image. The Hough transform is a technique which can be used to isolate features of a particular shape within an image. The implementation of the circle transform in OpenCV uses a tricky method called the Hough gradient method ( Link to Google Books ).
cvHoughCircles( ) is the function provided in OpenCV.
CvSeq* cvHoughCircles(
CvArr* image,
void* circle_storage,
int method,
double dp,
double min_dist,
double param1 = 100,
double param2 = 300,
int min_radius = 0,
int max_radius = 0
);
Following is a example code snippet.