java - Hough circle detection accuracy very low -
i trying detect circular shape image appears have definition. realize part of circle missing i've read hough transform doesn't seem should cause problem i'm experiencing.
input:
output:
code:
// read image mat src = highgui.imread("input.png"); // convert gray mat src_gray = new mat(); imgproc.cvtcolor(src, src_gray, imgproc.color_bgr2gray); // reduce noise avoid false circle detection //imgproc.gaussianblur( src_gray, src_gray, new size(9, 9), 2, 2 ); mat circles = new mat(); /// apply hough transform find circles imgproc.houghcircles(src_gray, circles, imgproc.cv_hough_gradient, 1, 1, 160, 25, 0, 0); // draw circles detected for( int = 0; < circles.cols(); i++ ) { double[] vcircle = circles.get(0, i); point center = new point(vcircle[0], vcircle[1]); int radius = (int) math.round(vcircle[2]); // circle center core.circle(src, center, 3, new scalar(0, 255, 0), -1, 8, 0); // circle outline core.circle(src, center, radius, new scalar(0, 0, 255), 3, 8, 0); } // save visualized detection. string filename = "output.png"; system.out.println(string.format("writing %s", filename)); highgui.imwrite(filename, src);
i have gaussian blur commented out because (counter intuitively) increasing number of equally inaccurate circles found.
is there wrong input image cause hough not work expect? parameters way off?
edit: first answer brought point min/max radius hint hough. resisted adding parameters example image in post 1 of thousands of images varying radii ~20 infinity.
if you'd set minradius
, maxradius
paramaeters properly, it'd give results.
for image, tried following parameters.
method - cv_hough_gradient mindist - 100 dp - 1 param1 - 80 param2 - 10 minradius - 250 maxradius - 300
i got following output
- note: tried in c++.
Comments
Post a Comment