Why HoughCircles returns 0 circles while trying to detect irises?

喜欢而已 提交于 2019-11-28 01:54:56

问题


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

The input image(eyes) is:

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:

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.

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


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/36018788/why-houghcircles-returns-0-circles-while-trying-to-detect-irises

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!