【问题标题】:no result after hough filter霍夫过滤后没有结果
【发布时间】:2013-03-15 17:03:39
【问题描述】:

在程序中,我使用了一个像这样的精明过滤器:

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

然后终端打印no表示没有返回结果,而cannyresult是一张有很多圆圈的图片。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 图片是8-bit, single-channel, grayscale input image. 吗?
  • 是的,但没有结果出来..奇怪。
  • 查看我的答案,该函数不会“返回”结果,您将向量作为参数传递给它 (vector<Vec3f> circles),然后它会用找到的圆圈填充向量。
  • 谢谢,把dp改成2后,终于可以了..
  • 请查看答案,投票给那些对您有帮助的人,如果其中一个人引导您解决问题,您应该点击它旁边的复选框将其选为官方答案。通过做这些事情,您可以帮助未来的访问者。

标签: python opencv hough-transform


【解决方案1】:

It's all about parameters,总是这样。 HoughCircles 中使用的参数播放fundamental role

我希望我能为您提供更多帮助,但没有输入图像可让我手忙脚乱。我与您分享的最后一个参考资料提供了指向其他答案的链接,其中包含实际源代码,证明了调整函数参数直到它们为您工作的重要性。

【讨论】:

  • 对于输入图像,我使用 8 位、单通道、灰度,其他我不知道它们是否会出现问题。现在还是没有结果。
【解决方案2】:

来自the documentation的用法是:

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

在哪里

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

示例用法:

#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;
}

需要注意的重要一点是:

circles = HoughCircles(gray, CV_HOUGH_GRADIENT...

你需要给它一个向量:

    vector<Vec3f> circles;

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

这更像是一种 C 风格的编程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    相关资源
    最近更新 更多