# Iris normalization and segmentation in opencv?

Hello All,

I am currently working on multibiometrics based on Face and Iris. However, i am having issues with Iris segmentation and normalization with opencv c++. Please can anyone throw more light on this. Thanks in advance.

edit retag close merge delete

2

what have you tried so far ?

( 2015-05-21 04:20:08 -0500 )edit

Sort by ยป oldest newest most voted

Hi Berek,

In iris recognition, you locate the pupil and then the Iris using canny edge and Hough transform.

First we calculte the pupil centriods using concept of contours:

static Mat getpupil(Mat& frame,Point& centroids){
Mat pupilImg = Mat(frame.size(), CV_8UC1);
Mat grayImg = Mat(frame.size(), CV_8UC1);
Mat tframe = frame;
Mat resImg;
inRange(frame, Scalar(28,28,28), Scalar(75,75,75), pupilImg);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
RNG rng(12345);
findContours(pupilImg, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
pupilImg.release();
pupilImg = frame.clone();
for (int i = 0; i < contours.size(); i++){
Moments mom = moments(contours[i]);
double area = mom.m00;
if (area > 50){
double pupilArea = area;
double x = mom.m10/area;
double y = mom.m01/area;
vector<vector<Point>> pupils = contours;
centroids = Point((int)x, (int)y);
Scalar color = Scalar(0, 0, 0);
drawContours(pupilImg, pupils,hierarchy[i][3], CV_RGB(0,0,0),CV_FILLED,8,hierarchy);
break;
}
}
return pupilImg;


}

Then we use Hough transform to find the Iris

static Mat getIris(Mat& frame,Point& centroid,int& rad){
Mat copyImg = frame.clone();
Mat Cf;
frame.copyTo(Cf);
Mat resImg = frame.clone();
Mat grayImg = Mat(frame.size(), CV_8UC1);
Mat Storage = Mat(frame.cols, 1, CV_32FC3);
int x1, y1;
Canny(frame, grayImg, 5, 70, 3);
GaussianBlur(grayImg, grayImg, Size(7, 7), 0);
vector<Vec3f> circles = getCircles(grayImg);

for (int i = 0; i < circles.size(); i++){
x1 = cvRound(circles[i][0]);
y1 = cvRound(circles[i][1]);
int x = centroid.x - rad;
int y = centroid.y - rad;
int w = rad * 2;
int h = w;
34    resImg = resImg(Rect(x,y,w,h));
Mat cropImg = Mat(Size(w,h), CV_8UC1);
resImg.copyTo(cropImg);
resImg = resImg(Rect(0, 0, resImg.cols, resImg.rows));
return cropImg;
}
return resImg;


}

Then i get error in line 34 above. OpencvError: Assertion failed (0 <=roi.x && 0 <= roi.width && ro.x + roi.width < m.cols && 0<=roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat

more

i can't see, where your centroid is initialized, but it complains, that the Rect is partly outside the image.

besides that, re-assigning a ROI to the original Mat might be a bad idea in a loop. maybe:

  Mat cropImg = Mat(Size(w,h), CV_8UC1);
resImg(Rect(x,y,w,h)).copyTo(cropImg); // leave resImg intact !


also:

  resImg = resImg(Rect(0, 0, resImg.cols, resImg.rows));


lt looks, like you wanted to restore the original size here, but it won't work, since you re-assigned resImg in line 34, again, - don't do that. avoid those re-assignments, and allow for a few more copies to be safe.

( 2015-05-21 08:00:09 -0500 )edit

Hi Berak,

Thanks for contribution, i am really grateful. However i still got the same error after some few steps. My centroids were computed in first method using contours (getPupil function). Please will really appreciate your response.

( 2015-05-21 09:36:57 -0500 )edit

Official site

GitHub

Wiki

Documentation