【问题标题】:Python 2.7 and OpenCV 3.3Python 2.7 和 OpenCV 3.3
【发布时间】:2018-02-11 13:27:47
【问题描述】:

我的代码中有一个问题,无法在 python2.7 和 opencv3.3 中检测某人的脸

import cv2
import numpy as np
faceDetect=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
cam=cv2.VideoCapture(0)
rec=cv2.face.LBPHFaceRecognizer_create()
rec.load("recognizer/trainningData.yml")
id=0
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_COMPLEX_SMALL,5,1,0,4)
while(True):
    ret,img=cam.read()
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces=faceDetect.detectMultiScale(gray,1.3,5)
    for(x,y,w,h) in faces:
        cv2.rextangle(img,(x,y),(x+w,y+h),(0,0,255),2)
        id,conf=rec.predict(gray[y:y+h,x:x+w])
        if id is 1:
            id="Zakir Naik"
        elif id is 2:
            id="Erdogan"
        elif id is 3:
            id="Fachrul"
        cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,255)
    cv2/imshow("Face",img)
    if(cv2.waitKey(1)==ord("q")):
        break;
cam.release()
cv2.destroyAllWindows()

输出

'cv2.face_LBPHFaceRecognizer' object has no attribute 'load'

【问题讨论】:

  • 您检查过LBPHFaceRecognizer_create 对象的文档吗?你能找到你试图调用的load 函数吗?

标签: python-2.7 opencv image-processing haar-classifier


【解决方案1】:

OpenCV2 has a load function

OpenCV3 does not

也许可以试试rec.read("recognizer/trainningData.yml")

【讨论】:

    猜你喜欢
    • 2018-02-13
    • 2014-02-14
    • 1970-01-01
    • 2015-05-10
    • 2014-01-01
    • 2018-02-20
    • 2014-04-29
    • 2014-01-24
    • 1970-01-01
    相关资源
    最近更新 更多