8

我试图用霍夫变换检测圆圈。使用霍夫变换检测圆圈

enter image description here

以我目前的代码,我可以检测低于

enter image description here

的一个,但我想找到我已经检测到的圈子里面的黑洞。 然而,改变houghcircle方法的参数对我没有帮助。其实它发现了不存在的圈子。

enter image description here

而且我已经试过农作物我已经找到了一圈并使用这个新的部件,也没帮我一个Hough变换。

这里是我的代码

#include <stdio.h> 
#include <iostream> 
#include "opencv2/core/core.hpp" 
#include "opencv2/features2d/features2d.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/calib3d/calib3d.hpp" 
#include "opencv2/nonfree/nonfree.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/opencv.hpp" // needs imgproc, imgcodecs & highgui 
using namespace cv; 
using namespace std; 

int main(int argc, char** argv) 
{ 
    Mat src, circleroi; 

    /// Read the image 
    src = imread("/Users/Rodrane/Documents/XCODE/test/mkedenemeleri/alev/delikli/gainfull.jpg", 2); 


    /// Convert it to gray 
// cvtColor(src, src_gray, CV_BGR2GRAY); 
     /// Reduce the noise so we avoid false circle detection 
    GaussianBlur(src, src, Size(3, 3), 2, 2); 
    // adaptiveThreshold(src,src,255,CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,9,14); 
    vector<Vec3f> circles,circlessmall; 
// Canny(src, src, 50 , 70, 3); 
     /// Apply the Hough Transform to find the circles 
    HoughCircles(src, circles, CV_HOUGH_GRADIENT, 1, src.rows/8, 200, 100, 0, 0); 

    /// Draw the circles detected 
    for(size_t i = 0; i < circles.size(); i++) 
    { 
     Point center(cvRound(circles[i][0]), cvRound(circles[i][4])); 
     int radius = cvRound(circles[i][5]); 
     // circle center 
    circle(src, center, 3, Scalar(0,255,0), -1, 8, 0); 
     // circle outline 
     circle(src, center, radius, Scalar(0,255,0), 3, 8, 0); 

     circleroi = src(Rect(center.x - radius, // ROI x-offset, left coordinate 
             center.y - radius, // ROI y-offset, top coordinate 
             2*radius,   // ROI width 
             2*radius)); 



    //  imshow("Hough Circle Transform Demo", circleroi); 


} 

    resize(src, src, Size(src.cols/2, src.rows/2)); 
// threshold(circleroi, circleroi, 50, 255,CV_THRESH_BINARY); 

    // cout<<circleroi<<endl; 
    imshow("asd",src); 

    // imwrite("/Users/Rodrane/Documents/XCODE/test/mkedenemeleri/alev/cikti/deliksiz.jpg",circleroi); 


    waitKey(0); 
    return 0; 
} 

更新:因为霍夫使用精明里面我用手动精明,看阉发现圆与否。 Canny(src,src,100,200,3); 0条结果,共有0条搜索结果(共1条) enter image description here

谢谢

+0

您是否尝试过不设阈值? HoughCircles在内部使用canny ... – Micka 2015-03-03 08:11:05

+0

图像上没有阈值。只有高斯模糊照明,但我也禁用它。 – 2015-03-03 08:12:20

+0

请问您是否可以发布带孔的图像,但没有黑色圆圈。前两张图片中我看不到任何黑洞。 – kkuilla 2015-03-03 09:12:27

回答

1

你设置HoughCircles参数minDist = src.rows/8,这是相当大的一个。所述docs解释:

minDist - 所检测到的圆的中心之间的最小距离。如果参数太小,除了真实的参数之外,可能会错误地检测到多个邻居圆。如果太大,可能会漏掉一些圈子。

该方法无法返回它找到的圆和您想要的圆,因为它们具有几乎相同的中心(在src.rows/8之内),只是大小不同。如果您将maxRadius设置为30左右的值以排除较大的圆圈,您是否会得到所需的较小圆圈?

+0

嗨,我试过HoughCircles(src,圈子,CV_HOUGH_GRADIENT,1,src。行/ 16(32,64),200,100,0,30);实际上找不到任何圆圈 – 2015-03-03 09:41:33

+0

嗯,也许'param2'太大了。值得在那里尝试较小的值。如果这不起作用,你可以在'Canny(src,edges,100,200)'中显示输出'edges'',并确保它首先找到内圆的边缘。 – 2015-03-03 09:50:41

+0

嗨,让我用canny结果更新我的问题。 – 2015-03-03 09:56:28