使用opencv python改善眼睛识别能力

时间:2019-06-25 13:55:21

标签: python opencv face-recognition haar-classifier

我正在尝试使用Python中的Haarcascade改善眼睛识别能力。 例如我有

initial image

但是生成的正方形与眼睛不一致。有可能改善这个结果吗?

image

import cv2

#load haarcascade_eye
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

# Load an color image
img = cv2.imread('clahe_2.jpg',cv2.IMREAD_COLOR)


#convert to gray scale to work with HAAR
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#read HAAR ade loop for find eye(s)
eyes = eye_cascade.detectMultiScale(gray)
for (ex,ey,ew,eh) in eyes:
    cv2.rectangle(img,(ex,ey),(ex+ew,ey+eh),(0,127,255),2)
    print(ex,ey,ex+ew,ey,eh)

#show eye(s) rectangle in color image
cv2.imshow('img',img)
#press any key to close
cv2.waitKey(0)
cv2.destroyAllWindows()

0 个答案:

没有答案