2013-03-07 67 views
0

我需要檢測使用了opencv2中可用的HoughCircle函數的眼睛圖片的虹膜。所以,在opencv for irc中使用hough circle函數查找分鐘圓圈

// 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邊緣檢測器使用sobel。建議請。

回答

1

霍夫變換的第五個參數是圓圈之間的minDist或最小距離(以像素爲單位)。您將此參數設置爲圖像中的行數除以8,這意味着任何重疊的圓圈(例如眼睛的瞳孔和虹膜)都不會因爲它們太靠近而被返回。

我會把這個數字設置爲一個變量而不是硬編碼它,並嘗試一組更小的數字,直到找到有效的東西。