为什么HoughCircles在尝试检测虹膜时会返回0个圆? [英] Why HoughCircles returns 0 circles while trying to detect irises?

查看:157
本文介绍了为什么HoughCircles在尝试检测虹膜时会返回0个圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测眼睛的虹膜,但是HoughCircles返回0个圆圈.

I am trying to detect the eyes' irises but HoughCircles returns 0 circles.

输入图像(眼睛)为:

然后我用这张图片做以下事情:

Then I made the following things with this image:

cvtColor(eyes, gray, CV_BGR2GRAY);
morphologyEx(gray, gray, 4,cv::getStructuringElement(cv::MORPH_RECT,cv::Size(3,3)));
threshold(gray, gray, 0, 255, THRESH_OTSU);
vector<Vec3f> circles;
HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 2, gray.rows/4);
if (circles.size())
        cout << "found" << endl;

所以最终的灰色图像看起来像这样:

So the final gray image looks like this:

我发现了这个问题使用HoughCircles进行检测和测量瞳孔和虹膜,但尽管与我的问题相似,但仍无济于事.

I've found this question Using HoughCircles to detect and measure pupil and iris but it didn't help me despite the similarity with my issue.

那么为什么HoughCircles在尝试检测虹膜时返回0个圆? 如果有人知道找到虹膜的更好方法,欢迎您.

So why does HoughCircles return 0 circles while trying to detect irises? If someone knows any better way to find irises, you are welcome.

推荐答案

对于相同的问题,我已经遇到了完全相同的问题.事实证明,houghcircles并不是检测不太理想的圆的好方法.

I have faced the exact same issue for the same problem. Turns out houghcircles is not a very good method for detecting not-so-well-formed circles.

在这些情况下,像MSER之类的功能检测方法效果更好.

Feature detection methods like MSER work better in these cases.

import cv2
import math
import numpy as np
import sys

def non_maximal_supression(x):
    for f in features:
        distx = f.pt[0] - x.pt[0]
        disty = f.pt[1] - x.pt[1]
        dist = math.sqrt(distx*distx + disty*disty)
        if (f.size > x.size) and (dist<f.size/2):
            return True

thresh = 70
img = cv2.imread(sys.argv[1])
bw = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

detector = cv2.FeatureDetector_create('MSER')
features = detector.detect(bw)
features.sort(key = lambda x: -x.size)

features = [ x for x in features if x.size > 70] 
reduced_features = [x for x in features if not non_maximal_supression(x)]

for rf in reduced_features:
    cv2.circle(img, (int(rf.pt[0]), int(rf.pt[1])), int(rf.size/2), (0,0,255), 3)

cv2.imshow("iris detection", img)
cv2.waitKey()

或者,您可以尝试使用卷积滤波器.

Alternatively you can try convolutional filters.

对于使用c ++ MSER的人,此处是基本要点.

For the ones who have issues with c++ MSER, here is a basic gist.

这篇关于为什么HoughCircles在尝试检测虹膜时会返回0个圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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