1

In the program I use a canny filter like this:

circles = cv2.HoughCircles(cannyresult,cv2.cv.CV_HOUGH_GRADIENT,1,10)
    if circles is None:
        print'no '

Then the terminal prints no which means there is no result back, and the cannyresult is a picture with a lot of circles. Can someone help me on this please?

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
user1510711
  • 113
  • 1
  • 1
  • 8
  • is the image an `8-bit, single-channel, grayscale input image.` ? – Awalias Mar 15 '13 at 17:10
  • Yes, but no result comes out.. strange. – user1510711 Mar 16 '13 at 09:46
  • see my answer, the function doesn't 'return' a result, you pass it a vector as an argument (`vector circles`), and it fills the vector out with the circles it finds. – Awalias Mar 16 '13 at 16:12
  • Thank you, after changing dp to 2, it works finally.. – user1510711 Mar 17 '13 at 00:14
  • Please review the answers, up vote those who have been helpful to you, and if one of them lead you to solve the problem you should click on the checkbox near it to select it as the official answer. By doing these things you are helping future visitors. – karlphillip Mar 31 '13 at 18:58

2 Answers2

0

from the documentation the usage is:

 Python: cv2.HoughCircles(image, method, dp, minDist[, circles[,
    param1[, param2[, minRadius[, maxRadius]]]]]) → circles

where

 circles – Output vector of found circles. Each vector is encoded as a
 3-element floating-point vector (x, y, radius)

with example usage:

#include <cv.h>
#include <highgui.h>
#include <math.h>

using namespace cv;

int main(int argc, char** argv)
{
    Mat img, gray;
    if( argc != 2 && !(img=imread(argv[1], 1)).data)
        return -1;
    cvtColor(img, gray, CV_BGR2GRAY);
    // smooth it, otherwise a lot of false circles may be detected
    GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
    vector<Vec3f> circles;
    HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
                 2, gray->rows/4, 200, 100 );
    for( size_t i = 0; i < circles.size(); i++ )
    {
         Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
         int radius = cvRound(circles[i][2]);
         // draw the circle center
         circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
         // draw the circle outline
         circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
    }
    namedWindow( "circles", 1 );
    imshow( "circles", img );
    return 0;
}

the important bit to notice is that instead of:

circles = HoughCircles(gray, CV_HOUGH_GRADIENT...

you need to pass it a vector:

    vector<Vec3f> circles;

    HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
                 2, gray->rows/4, 200, 100 );

This is more of a C style of programming

Awalias
  • 2,027
  • 6
  • 31
  • 51
0

It's all about parameters, it always is. The parameters used in HoughCircles play a fundamental role.

I wish I could help you more, but without an input image to work with my hands are tied. The last reference I shared with you provides links to other answers with actual source code that demonstrates the importance of tweaking the function parameters until they work for you.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • for the input image, i use a 8 bit, sigle channel, grayscale, the others i don't know if they can be a problem. Still no result now. – user1510711 Mar 16 '13 at 10:10