Iris and pupil detection in image with Java and OpenCV

3.1k views Asked by At

I have got a known problem with iris and pupil detection in images. I've already read some topics (such as:

What are the correct usage/parameter values for HoughCircles in OpenCV for Iris detection? pupil Detection and cvHoughCircles? Using HoughCircles to detect and measure pupil and iris HoughCircles Parameters to recognise balls

about this issue, but still can't find solution of my problem.

I've got a eye image and what I want to do is detect iris and pupil. My problem is that, I can't select good parameter values.

This is my input sample picture: Input picture And this is my output: enter image description here

My code is posted below.

 Mat src = Highgui.imread("in.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);       
 Mat des = new Mat(src.rows(), src.cols(), src.type());
 Imgproc.GaussianBlur(src,src, new Size(3,3),0,0); 
 Imgproc.Canny(src, dst,  5, 10);
 Mat circles = new Mat();
 Imgproc.HoughCircles(source, circles, Imgproc.CV_HOUGH_GRADIENT, 1.0, 20.0, 70.0, 30.0, 3, 100);
 //draw circles code here

I want to have a circled pupil and iris. Can somebody post correct values for my circle detection?
I also have few questions:

1) Is better to use Canny or Sobel filter?

2) Can I do this detection better, more flexible?

3) Can you simple explain me what exacly means HoughCircles parameters - (from OpenCV javadoc)

* @param dp Inverse ratio of the accumulator resolution to the image
  * resolution. For example, if <code>dp=1</code>, the accumulator has the same
  * resolution as the input image. If <code>dp=2</code>, the accumulator has half
  * as big width and height.
* @param param1 First method-specific parameter. In case of <code>CV_HOUGH_GRADIENT</code>,
  * it is the higher threshold of the two passed to the "Canny" edge detector
  * (the lower one is twice smaller).
* @param param2 Second method-specific parameter. In case of <code>CV_HOUGH_GRADIENT</code>,
  * it is the accumulator threshold for the circle centers at the detection
  * stage. The smaller it is, the more false circles may be detected. Circles,
1

There are 1 answers

0
Vasanth On

Hough circles is not a very good method for iris/pupil detection. It is not very reliable and you'll always end up tuning too many parameters than you should.

After some basic thresholding or canny edge detection, feature detection methods like MSER work better in these cases. Here is a similar question with a solution.

Since you have a good resolution image, if you are looking to measure them or want something very accurate, I would suggest this blog. It has detailed explanation on the steps involved.