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 mask = 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++){
rad = cvRound(circles[i][2]);
x1 = cvRound(circles[i][0]);
y1 = cvRound(circles[i][1]);
circle(mask, centroid, rad, CV_RGB(255, 255, 255), CV_FILLED);
//circle(mask, Point(x1,y1), rad, CV_RGB(255, 255, 255), CV_FILLED);
bitwise_not(mask, mask);
subtract(frame,copyImg,resImg,mask);
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
what have you tried so far ?