Circle detection using the Hough transform

I am trying to detect circles using the hough transform.

enter image description here

With my current code, I can find below

enter image description here

But I want to find a black hole inside the circle that I discovered. however, changing the parameters of the houghcircle method did not help me. In fact, he found circles that do not exist.

enter image description here

I also tried to crop the circle that I found, and do another hough transform on this new part, it also did not help me.

here is my code

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

Update : since hough uses canny inside, I manually use canny to see if he finds a circle or not.

here are the tricky results with Canny (src, src, 100, 200.3); enter image description here

Thank you

+8
c ++ image-processing opencv hough-transform feature-detection
source share
1 answer

You set one of the parameters HoughCircles minDist = src.rows/8 , which is quite large. docs explain:

minDist . The minimum distance between the centers of the detected circles. If the parameter is too small, several adjacent circles can be falsely detected in addition to the true one. If it is too large, some circles may be skipped.

The method cannot return both the circles it finds and the circle you want, since they have almost the same center (accurate to src.rows/8 ), only different sizes. If you set the maxRadius parameter to about 30 to exclude a larger circle, do you get the desired smaller circle?

+1
source share

All Articles