在opencv中使用hough circle函数查找用于虹膜的小圈

时间:2013-03-07 19:20:41

标签: opencv edge-detection hough-transform iris-recognition

我需要使用opencv2中提供的HoughCircle函数来检测眼图的虹膜。所以,

// 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 );
               }

所以这是我的代码,只检测到眼睛的外部部分,因为我希望检测到瞳孔和虹膜边界并且没有发生,我提到链接OpenCV: Using Hough Circle Transformation to detect iris 但它不会那样工作。而不是canny边缘探测器已经使用了索贝尔。建议请。

1 个答案:

答案 0 :(得分:1)

Hough变换的第五个参数是minDist,或圆之间的最小距离(以像素为单位)。您将此参数设置为图像中的行数除以8,这意味着任何重叠的圆圈(例如眼睛的瞳孔和虹膜)将不会返回,因为它们距离太近。

我将此数字设置为变量而不是硬编码,并尝试使用一组小得多的数字,直到找到有用的数字。

相关问题