Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect/Fitting Circles using Hough Transform in OpenCV 2.4.6
    text
    copied!<p>The objective is to detect the 5 white circles in the image.The test image in which the circles have to be detected is the one shown here <a href="http://depot.tu-dortmund.de/get/z4p8g" rel="nofollow">640x480</a><br> Please download the original image here,<a href="http://depot.tu-dortmund.de/get/vnegf" rel="nofollow">1280x1024</a></p> <p>I am using different methods to bring out a evaluation of various circle/ellipse detection methods. But somehow I am not able to fix my simple Hough transform code. It does not detect any circles. I am not clear whether the problem is with pre-processing step, or the parameters of the HoughCircle. I have gone through all the similar questions in the forum, but still not able to fix the issue. This is my code. Please help me in this regards..</p> <p>Header file</p> <pre><code>#ifndef IMGPROCESSOR_H #define IMGPROCESSOR_H // OpenCV Library #include &lt;opencv2\opencv.hpp&gt; #include &lt;iostream&gt; using namespace cv; using namespace std; class ImgProcessor{ public: Mat OpImg ; ImgProcessor(); ~ImgProcessor(); //aquire filter methods to image int Do_Hough(Mat IpImg); }; #endif /* ImgProcessor_H */ </code></pre> <p>Source file</p> <pre><code>#include "ImgProcessor.h" #include &lt;opencv2\opencv.hpp&gt; #include "opencv2\imgproc\imgproc.hpp" #include "opencv2\imgproc\imgproc_c.h" #include &lt;vector&gt; using namespace cv; ImgProcessor::ImgProcessor(){ return; } ImgProcessor::~ImgProcessor(){ return; } //Apply filtering for the input image int ImgProcessor::Do_Hough(Mat IpImg) { //Parameter Initialization________________________________________________________ double sigma_x, sigma_y, thresh=250, max_thresh = 255; int ksize_w = 5 ; int ksize_h = 5; sigma_x = 0.3*((ksize_w-1)*0.5 - 1) + 0.8 ; sigma_y = 0.3*((ksize_h-1)*0.5 - 1) + 0.8 ; vector&lt;Vec3f&gt; circles; //Read the image as a matrix Mat TempImg; //resize(IpImg, IpImg ,Size(), 0.5,0.5, INTER_AREA); //Preprocessing__________________________________________________________ //Perform initial smoothing GaussianBlur( IpImg, TempImg, Size(ksize_w, ksize_h),2,2); //perform thresholding threshold(TempImg,TempImg, thresh,thresh, 0); //Remove noise by gaussian smoothing GaussianBlur( TempImg, TempImg, Size(ksize_w, ksize_h),2,2); /*imshow("Noisefree Image", TempImg); waitKey(10000);*/ //Obtain edges Canny(TempImg, TempImg, 255,240 , 3); imshow("See Edges", TempImg); waitKey(10000); //Increase the line thickness //dilate(TempImg,TempImg,0,Point(-1,-1),3); //Hough Circle Method______________________________________________________________ // Apply the Hough Transform to find the circles HoughCircles( TempImg, circles, 3, 1, TempImg.rows/32, 255, 240, 5, 0 ); // Draw the circles detected for( size_t i = 0; i &lt; circles.size(); i++ ) { Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); int radius = cvRound(circles[i][2]); // circle center circle( IpImg, center, 3, Scalar(0,255,0), -1, 8, 0 ); // circle outline circle( IpImg, center, radius, Scalar(0,0,255), 3, 8, 0 ); } // Show your results namedWindow( "Hough Circle Transform", WINDOW_AUTOSIZE ); imshow( "Hough Circle Transform", IpImg ); // waitKey(0); return 0; } int main(int argc, char** argv) { ImgProcessor Iclass; //char* imageName = argv[1]; string imageName = "D:/Projects/test_2707/test_2707/1.bmp"; Mat IpImg = imread( imageName ); cvtColor(IpImg, IpImg,6,CV_8UC1); Iclass.Do_Hough(IpImg); /*Iclass.Do_Contours(IpImg);*/ return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload