我使用的是Python 2.7和OpenCV 3.2我使用的是Windows 64位。 我正在处理人脸识别代码,我想使用OpenCV FaceRecognizer
recognizer = cv2.face.createFisherFaceRecognizer()
但是当我运行代码时出现此错误,
AttributeError:'模块'对象没有属性' createFisherFaceRecognizer'
我也试着这样写
recognizer = cv2.createFisherFaceRecognizer()
但仍然得到相同的错误
这是代码,代码是kivy代码的一部分
def FaceRecognizer():
recognizer = cv2.face.createFisherFaceRecognizer()
recognizer.load('Trainer/Trainer.yml')
face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam = cv2.VideoCapture(0)
font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1)
while (True):
retval,image = cam.read() # reading image from cam
print np.shape(image)
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) # converting image to gray image
faces = face_detector.detectMultiScale(gray_image,1.3,5)
''' detectMultiScale, detects objects of different sizes in the input image.
the detected objects are returned as a list of rectangles
'''
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+w, y+h), (255,0,0), 2)
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
if(conf<50):
Id="Aladdin Hammodi"
else:
Id= "Unknown"
cv2.cv.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255)
cv2.imshow('frame',image)
if cv2.waitKey(100) & 0xFF == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
output = "Recognition is done"
return output