使用HoughCircles来检测和测量瞳孔和虹膜 [英] Using HoughCircles to detect and measure pupil and iris

查看:163
本文介绍了使用HoughCircles来检测和测量瞳孔和虹膜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV,更具体地说是它的HoughCircles来检测和测量瞳孔和虹膜,目前我一直在玩这个函数中的一些变量,因为它要么返回0个圆圈,要么过量。以下是我正在使用的代码和测试图像。



测量光圈的代码:

  eye1 = [self increaseIn:eye1 Contrast:2 andBrightness:0]; 

cv :: cvtColor(eye1,eye1,CV_RGBA2RGB);
cv :: bilateralFilter(eye1,eye2,75,100,100);

cv :: vector< cv :: Vec3f>界;

cv :: cvtColor(eye2,eye1,CV_RGBA2GRAY);

cv :: morphologyEx(eye1,eye1,4,cv :: getStructuringElement(cv :: MORPH_RECT,cv :: Size(3,3)));
cv :: threshold(eye1,eye1,0,255,cv :: THRESH_OTSU);

eye1 = [self circleCutOut:eye1尺寸:50];

cv :: GaussianBlur(eye1,eye1,cv :: Size(7,7),0);

cv :: HoughCircles(eye1,circles,CV_HOUGH_GRADIENT,2,eye1.rows / 4);

测量学生的代码:

  eye1 = [self increaseBlackPupil:eye1]; 
cv :: Mat eye2 = cv :: Mat :: zeros(eye1.rows,eye1.cols,CV_8UC3);

eye1 = [self increaseIn:eye1 Contrast:2 andBrightness:0];

cv :: cvtColor(eye1,eye1,CV_RGBA2RGB);
cv :: bilateralFilter(eye1,eye2,75,100,100);

cv :: threshold(eye2,eye1,25,255,CV_THRESH_BINARY);

cv :: SimpleBlobDetector :: Params params;
params.minDistBetweenBlobs = 75.0f;
params.filterByInertia = false;
params.filterByConvexity = false;
params.filterByCircularity = false;
params.filterByArea = true;
params.minArea = 50;
params.maxArea = 500;

cv :: Ptr< cv :: FeatureDetector> blob_detector = new cv :: SimpleBlobDetector(params);
blob_detector-> create(SimpleBlob);
cv :: vector< cv :: KeyPoint>关键点;
blob_detector-> detect(eye1,keypoints);



我知道图像很粗糙,我也一直试图找到一种方法来清理它并使边缘更清晰。



所以我的问题是明白:我可以做些什么来调整函数HoughCircles中的参数或更改图像以检测虹膜和瞳孔? / p>

谢谢

解决方案

好的,没有试验太多,我理解的是什么是你在使用霍夫圆检测器之前只对图像应用了双边滤镜。



在我看来,你需要在这个过程中加入一个阈值步骤。



我拍了你在帖子中提供的样本图片并使其经历了以下步骤:


  1. 转换为灰度


  2. 形态渐变


  3. 阈值


  4. hough circle detection。


在阈值处理步骤之后,我的左眼只有以下图片:





这里是代码:



greyscale:

  cvCvtColor(im_rgb,im_rgb,CV_RGB2GRAY); 

形态:

  cv :: morphologyEx(im_rgb,im_rgb,4,cv :: getStructuringElement(cv :: MORPH_RECT,cv :: Size(size,size))); 

阈值:

  cv :: threshold(im_rgb,im_rgb,low,high,cv :: THRESH_OTSU); 

hough circle detection:

  cv :: vector< cv :: Vec3f>界; 
cv :: HoughCircles(im_rgb,circles,CV_HOUGH_GRADIENT,2,im_rgb.rows / 4);

现在打印时:

  NSLog(@找到%ld cirlces,circles.size()); 

我得到:

 找到1个cirlces

希望这有帮助。


I'm trying to use OpenCV, more specifically its HoughCircles to detect and measure the pupil and iris, currently I've been playing with some of the variables in the function, because it either returns 0 circles, or an excessive amount. Below is the code and test image I'm using.

Code for measuring iris:

 eye1 = [self increaseIn:eye1 Contrast:2 andBrightness:0];

cv::cvtColor(eye1, eye1, CV_RGBA2RGB);
cv::bilateralFilter(eye1, eye2, 75, 100, 100);

cv::vector<cv::Vec3f> circles;

cv::cvtColor(eye2, eye1, CV_RGBA2GRAY);

cv::morphologyEx(eye1, eye1, 4, cv::getStructuringElement(cv::MORPH_RECT,cv::Size(3, 3)));
cv::threshold(eye1, eye1, 0, 255, cv::THRESH_OTSU);

eye1 = [self circleCutOut:eye1 Size:50];

cv::GaussianBlur(eye1, eye1, cv::Size(7, 7), 0);

cv::HoughCircles(eye1, circles, CV_HOUGH_GRADIENT, 2, eye1.rows/4);

Code for measuring pupil:

eye1 = [self increaseBlackPupil:eye1];
    cv::Mat eye2 = cv::Mat::zeros(eye1.rows, eye1.cols, CV_8UC3);

    eye1 = [self increaseIn:eye1 Contrast:2 andBrightness:0];

    cv::cvtColor(eye1, eye1, CV_RGBA2RGB);
    cv::bilateralFilter(eye1, eye2, 75, 100, 100);

    cv::threshold(eye2, eye1, 25, 255, CV_THRESH_BINARY);

    cv::SimpleBlobDetector::Params params;
    params.minDistBetweenBlobs = 75.0f;
    params.filterByInertia = false;
    params.filterByConvexity = false;
    params.filterByCircularity = false;
    params.filterByArea = true;
    params.minArea = 50;
    params.maxArea = 500;

    cv::Ptr<cv::FeatureDetector> blob_detector = new cv::SimpleBlobDetector(params);
    blob_detector->create("SimpleBlob");
    cv::vector<cv::KeyPoint> keypoints;
    blob_detector->detect(eye1, keypoints);

I know the image is rough, I've been also trying to find a way to clean it up and make the edges clearer.

So my question to put it plainly: What can I do to adjust the parameters in the function HoughCircles or changes to the images to make the iris and pupil detected?

Thanks

解决方案

Ok, without experimenting too much, what I understand is that you've only applied a bilateral filter to the image before using the Hough circle detector.

In my opinion, you need to include a thresholding step into the process.

I took your sample image that you provided in the post and made it undergo the following steps:

  1. conversion to greyscale

  2. morphological gradient

  3. thresholding

  4. hough circle detection.

after the thresholding step, I got the following image for the left eye only:

here's the code:

greyscale:

   cvCvtColor(im_rgb,im_rgb,CV_RGB2GRAY);

morphology:

      cv::morphologyEx(im_rgb,im_rgb,4,cv::getStructuringElement(cv::MORPH_RECT,cv::Size(size,size)));

thresholding:

    cv::threshold(im_rgb, im_rgb, low, high, cv::THRESH_OTSU);

hough circle detection:

    cv::vector<cv::Vec3f> circles;
    cv::HoughCircles(im_rgb, circles, CV_HOUGH_GRADIENT, 2, im_rgb.rows/4); 

Now when I print:

    NSLog(@"Found %ld cirlces", circles.size());

I get:

     "Found 1 cirlces"

Hope this helps.

这篇关于使用HoughCircles来检测和测量瞳孔和虹膜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆