Search code examples
c++opencvimage-processinghough-transform

Hough Circle on binary images


I'm trying to create a generic function which always finds my 3 color balls. (Red, yellow and white). I spend a lot of time to search a solution, and it's pretty hard... For the moment, first, I use the Canny filter (I use the Otsu method to determine the lower and highter parameter) and I call the Hough Circle method by incrementing param2 until I find 3 circles.

while (!findCircles){
    Imgproc.HoughCircles(hough, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 100, 200, low, 20, 100); //find3Circles = true;  
    if (circles.cols() == 3){
        findCircles = true;
    }       
    low++;
 }

It doesn't work very well...

If someone vote up for my question, i could post images (i have no enough points...) Please, if someone found the solution, it would be nice to tell me.


Solution

  • I think that you should base you method on finding colors, not shapes or at least you should stary with finding colors and then find shapes. Here there is good(it uses old OpenCV API, but everything else is fine) article describing how to perform color based object tracking in OpenCV. The general idea is simple - convert image to HSV color space, use inRange function to find pixels which might be your objects and then track them (most likely you will have to filter the pixels - find biggest contour or contour which shape is close to circle). Note that you will need to call inRange function 3 times (one for each ball).