【问题标题】:Can we use Haar Classifier to detect Iris of an eye as done for face and eyes?我们可以使用 Haar 分类器来检测眼睛的虹膜,就像检测面部和眼睛一样吗?
【发布时间】:2019-07-17 11:21:59
【问题描述】:

我目前正在尝试检测给定图像中的虹膜和瞳孔。网上看到的所有方法都是先检测人脸,然后是眼睛,然后使用阈值处理、霍夫变换和轮廓处理来最终检测瞳孔。

如果我们已经有大量的瞳孔数据集,我们不能像在人脸和眼睛的情况下那样训练一个 Haar 分类器来检测眼睛的虹膜吗?这有什么不应该起作用的原因吗?

目前,我有一个使用基于非 haar 的方法的部分工作解决方案。

一个工作代码示例

import math 
import cv2 

eye_cascade = cv2.CascadeClassifier('./cascade_files/haarcascade_eye.xml')

if eye_cascade.empty():
  raise IOError('Unable to load the eye cascade classifier xml file')

cap = cv2.VideoCapture(0)
ds_factor = 0.5
ret, frame = cap.read()
contours = []

while True: 
  ret, frame = cap.read() 
  frame = cv2.resize(frame, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA)
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  eyes = eye_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=1)
  for (x_eye, y_eye, w_eye, h_eye) in eyes:
    pupil_frame = gray[y_eye:y_eye + h_eye, x_eye:x_eye + w_eye]
    ret, thresh = cv2.threshold(pupil_frame, 80, 255, cv2.THRESH_BINARY)
    cv2.imshow("threshold", thresh)
    im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    print(contours)

    for contour in contours:
      area = cv2.contourArea(contour)
      rect = cv2.boundingRect(contour)
      x, y, w, h = rect
      radius = 0.15 * (w + h)

      area_condition = (100 <= area <= 200)
      symmetry_condition = (abs(1 - float(w)/float(h)) <= 0.2)
      fill_condition = (abs(1 - (area / (math.pi * math.pow(radius, 2.0)))) <= 0.4)
      cv2.circle(frame, (int(x_eye + x + radius), int(y_eye + y + radius)), int(1.3 * radius), (0, 180, 0), -1)

  cv2.imshow('Pupil Detector', frame)
  c = cv2.waitKey(1) 
  if c == 27: 
    break

cap.release() 
cv2.destroyAllWindows()

示例输出:

【问题讨论】:

    标签: python opencv computer-vision


    【解决方案1】:

    是的,您可以使用 Haar Cascade 分类器上的样本图像直接训练瞳孔检测器。如果您不受限于高吞吐量的小型硬件,那么我建议您使用深度学习在同一数据集上进行训练,您可以获得更好的结果。

    【讨论】:

    • 更好的答案会显示一些代码!否则,此类建议更适合作为 cmets。
    猜你喜欢
    • 2016-05-19
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2011-09-01
    • 2012-03-20
    • 2012-08-27
    相关资源
    最近更新 更多