Python Pupil检测

时间:2016-09-23 15:30:03

标签: python opencv image-processing

我正试图检测图像中的瞳孔。我使用haarcascade分类器检测到面部和眼睛,在那些眼睛中我使用Hough Transform来检测圆圈(瞳孔)。以下是我的代码

import matplotlib
import matplotlib.pyplot as plt
import cv2
import sys
import numpy as np
import os

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eyeCascade= cv2.CascadeClassifier('haarcascade_eye.xml')

img = cv2.imread('me.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

faces = faceCascade.detectMultiScale(img)

for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x+w, y+h), 255, 2)
    roi = img[y:y+h, x:x+w]

    eyes = eyeCascade.detectMultiScale(roi)
    for (ex,ey,ew,eh) in eyes:
            cv2.rectangle(roi,(ex,ey),(ex+ew,ey+eh), 255, 2)

    circles = cv2.HoughCircles(eyes,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)

    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
        cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)

cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

当我运行此代码时,我收到错误

Traceback (most recent call last):
  File "D:\Acads\7.1 Sem\BTP\FaceDetect-master\hough transform.py", line 25, in <module>
    circles = cv2.HoughCircles(eyes,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
error: ..\..\..\opencv-3.1.0\modules\core\src\array.cpp:2494: error: (-206) Unrecognized or unsupported array type in function cvGetMat

请帮助我谢谢

0 个答案:

没有答案