在OpenCV for Iris检测中,HoughCircles的正确用法/参数值是什么? [英] What are the correct usage/parameter values for HoughCircles in OpenCV for Iris detection?

查看:1777
本文介绍了在OpenCV for Iris检测中,HoughCircles的正确用法/参数值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读这个主题,但无法得到关于 HoughCircles (特别是<$ c $后的那些)的用法和参数的纯英语 c> CV_HOUGH_GRADIENT )。

I've been reading about the subject but cannot get the idea in "plain English" about the usage and parameters for HoughCircles (specially the ones after CV_HOUGH_GRADIENT).

累加器阈值是多少? 100票是一个正确的价值吗?

What's an accumulator threshold? Are 100 "votes" a right value?

我可以找到并掩盖学生,并通过 Canny 函数,但我还在努力超越那个,我的问题是 HoughCircles 函数。似乎没有找到Iris的圈子,我不知道为什么。

I could find and "mask" the pupil, and worked my way through the Canny function, but I'm struggling beyond that and my problem is the HoughCircles function. There seems to be failing at finding the Iris' circle and I don't know why.

这是我工作的函数on:

And this is the function I'm working on:

def getRadius(area):
    r = 1.0
    r = math.sqrt(area/3.14)
    return (r)

def getIris(frame):
    grayImg = cv.CreateImage(cv.GetSize(frame), 8, 1)
    cv.CvtColor(frame,grayImg,cv.CV_BGR2GRAY)
    cv.Smooth(grayImg,grayImg,cv.CV_GAUSSIAN,9,9)
    cv.Canny(grayImg, grayImg, 32, 2)
    storage = cv.CreateMat(grayImg.width, 1, cv.CV_32FC3)
    minRad = int(getRadius(pupilArea))
    circles = cv.HoughCircles(grayImg, storage, cv.CV_HOUGH_GRADIENT, 2, 10,32,200,minRad, minRad*2)
    cv.ShowImage("output", grayImg)
    while circles:
        cv.DrawContours(frame, circles, (0,0,0), (0,0,0), 2)
        # this message is never shown, therefore I'm not detecting circles
        print "circle!"
        circles = circles.h_next()
    return (frame)


推荐答案

HoughCircles 可能有点棘手,我建议通过此线程。在那里一群人,包括我;),讨论如何使用它。关键参数是 param2 ,即所谓的累加器阈值。基本上,越高,你得到的圈越少。这些圈子具有更高的正确概率。最佳值对于每个图像是不同的。我认为最好的方法是使用 param2 上的参数搜索。也就是说。继续尝试值,直到满足您的条件(例如:有2个圈子,或最多不重叠的圈子数等)。我有一些代码,对'param2'进行二进制搜索,所以它很快满足标准。

HoughCircles can be kind of tricky, I suggest looking through this thread. Where a bunch of people, including me ;), discuss how to use it. The key parameter is param2, the so-called accumulator threshold. Basically, the higher it is the less circles you get. And these circles have a higher probability of being correct. The best value is different for every image. I think the best approach is to use a parameter search on param2. Ie. keep on trying values until your criteria is met (such as: there are 2 circles, or max. number of circles that are non-overlapping, etc.). I have some code that does a binary search on 'param2', so it meet the criteria quickly.

另一个关键因素是预处理,尝试减少噪点,并简化图像。一些模糊/阈值/ canny的组合是有益的。

The other crucial factor is pre-processing, try to reduce noise, and simplify the image. Some combination of blurring/thresholding/canny is good for this.

无论如何,我得到:

从您的uploded图片,使用此代码:

From your uploded image, using this code:

import cv
import numpy as np

def draw_circles(storage, output):
    circles = np.asarray(storage)
    for circle in circles:
        Radius, x, y = int(circle[0][3]), int(circle[0][0]), int(circle[0][4])
        cv.Circle(output, (x, y), 1, cv.CV_RGB(0, 255, 0), -1, 8, 0)
        cv.Circle(output, (x, y), Radius, cv.CV_RGB(255, 0, 0), 3, 8, 0)    

orig = cv.LoadImage('eyez.png')
processed = cv.LoadImage('eyez.png',cv.CV_LOAD_IMAGE_GRAYSCALE)
storage = cv.CreateMat(orig.width, 1, cv.CV_32FC3)
#use canny, as HoughCircles seems to prefer ring like circles to filled ones.
cv.Canny(processed, processed, 5, 70, 3)
#smooth to reduce noise a bit more
cv.Smooth(processed, processed, cv.CV_GAUSSIAN, 7, 7)

cv.HoughCircles(processed, storage, cv.CV_HOUGH_GRADIENT, 2, 32.0, 30, 550)
draw_circles(storage, orig)

cv.ShowImage("original with circles", orig)
cv.WaitKey(0)

更新

我意识到我有点错过了您的问题!您实际上想要找到 iris 边缘。他们不是那么清楚地定义,像学生。因此,我们需要尽可能帮助 HoughCircles 。我们可以这样做:

I realise I somewhat miss-read your question! You actually want to find the iris edges. They are not so clearly defined, as the pupils. So we need to help HoughCircles as much as possible. We can do this, by:


  1. 指定虹膜的大小范围(我们可以从瞳孔大小计算出合理的范围)。

  2. 增加圆心之间的最小距离(我们知道两个光圈不能重叠,因此我们可以将其设置为最小光圈大小)

然后我们需要在 param2 上再次进行param搜索。将上述代码中的HoughCircles替换为:

And then we need to do a param search on param2 again. Replacing the 'HoughCircles' line in the above code with this:

cv.HoughCircles(processed, storage, cv.CV_HOUGH_GRADIENT, 2, 100.0, 30, 150,100,140)

获取我们:

>

这不是太糟糕。

这篇关于在OpenCV for Iris检测中,HoughCircles的正确用法/参数值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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