Color detection on HoughCircles using OpenCV

狂风中的少年 提交于 2019-12-04 17:54:39

If the balls each have a uniform color, you can check the color at the center:

CvMemStorage* storage = cvCreateMemStorage(0);
cvSmooth(image, image, CV_GAUSSIAN, 5, 5 );
CvSeq* results = cvHoughCircles(
image,
storage,
CV_HOUGH_GRADIENT,
2,
image->width/10
);
for( int i = 0; i < results->total; i++ ) 
{
float* p = (float*) cvGetSeqElem( results, i );
CvPoint center = cvPoint( cvRound( p[0] ), cvRound( p[1] ) );
CvScalar c = cvGet2D(image, center.x, center.y); //color of the center
}

Haven't tested the code but it should be ok.

EDIT:

Ooops, I forgot one parameter from the Get2D method, the actual image from which to get the color. Changed to the correct form.

We have written our own blob detection library in the open source vision framework: http://www.simplecv.org

The code to do what you want is as easy as:

img = Image("/path/to/image.png")
blobs = img.findBlobs()
circle_blobs = blobs.filter(blobs.isCircle() == True)
list_of_blobs_colors = circle_blobs.meanColor()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!