To find minute circles using hough circle function in opencv for iris

≡放荡痞女 提交于 2019-12-13 06:14:54

问题


I need to detect the iris of the eye picture I have using HoughCircle function thats available in opencv2. So ,

// Read the image
       src = imread("D:/001R_3.png");
       if( !src.data )
       { return -1; }

       /// Convert it to gray
     cvtColor( src, src_gray, CV_BGR2GRAY );

       /// Reduce the noise so we avoid false circle detection
      GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );

       /////////////
       /// Generate grad_x and grad_y
        Mat grad_x, grad_y;
        Mat abs_grad_x, abs_grad_y;

       Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
         convertScaleAbs( grad_x, abs_grad_x );

     /// Gradient Y
       //Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
        Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
       convertScaleAbs( grad_y, abs_grad_y );

     /// Total Gradient (approximate)
        addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );
      ///////////////
       vector<Vec3f> circles;

        /// Apply the Hough Transform to find the circles
       HoughCircles( grad, circles, CV_HOUGH_GRADIENT, 1, grad.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][1]));
          cout<<center;
           int radius = cvRound(circles[i][2]);
            // circle center
           cout<<radius;
          circle(src, center, 3, Scalar(0,255,0), -1, 8, 0 );
          // circle outline
          circle(src, center, radius, Scalar(0,0,255), 3, 8, 0 );
           }

          /// Show your results
            namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
            imshow( "Hough Circle Transform Demo",src );
               }

So here is my code, only the outer portion of the eye is detected where as i want the pupil and the iris boundary to be detected and thats not happening , I referred the link OpenCV: Using Hough Circle Transformation to detect iris but it doesn't work that way. Instead of canny edge detector have used sobel. Suggestions please.


回答1:


The fifth parameter of the Hough transform is the minDist, or minimum distance (in pixels) between circles. You have this parameter set to the number of rows in the image divided by 8, which means that any overlapping circles (such as the pupil and iris of your eye) will not be returned because they are too close together.

I'd set this number as a variable instead of hard-coding it, and experiment with a set of much smaller numbers until you find something that works.



来源:https://stackoverflow.com/questions/15279892/to-find-minute-circles-using-hough-circle-function-in-opencv-for-iris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!