Распознавание лиц с использованием opencv 3.1.0 на Raspberry Pi3

Я использую opencv 3.1.0, python на raspberry pi 3 для распознавания лиц, и я использовал приведенный ниже код, но я получаю сообщение об ошибке, пожалуйста, как мне это исправить, я следил за многочисленными сайтами о том, как это исправить, но ни один из них не работал

ОШИБКА

recognizer= cv2.createLBPHFaceRecognizer()

AttributeError: module ‘cv2’ has no attribute

КОД

import cv2,os
import numpy as np
from PIL import Image

recognizer = cv2.createLBPHFaceRecognizer()
detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml");

def getImagesAndLabels(path):
    #get the path of all the files in the folder
    imagePaths=[os.path.join(path,f) for f in os.listdir(path)] 
    #create empth face list
    faceSamples=[]
    #create empty ID list
    Ids=[]
    #now looping through all the image paths and loading the Ids and the images
    for imagePath in imagePaths:
        #loading the image and converting it to gray scale
        pilImage=Image.open(imagePath).convert('L')
        #Now we are converting the PIL image into numpy array
        imageNp=np.array(pilImage,'uint8')
        #getting the Id from the image
        Id=int(os.path.split(imagePath)[-1].split(".")[1])
        # extract the face from the training image sample
        faces=detector.detectMultiScale(imageNp)
        #If a face is there then append that in the list as well as Id of it
        for (x,y,w,h) in faces:
            faceSamples.append(imageNp[y:y+h,x:x+w])
            Ids.append(Id)
    return faceSamples,Ids

faces,Ids = getImagesAndLabels('dataSet')
recognizer.train(faces, np.array(Ids))
recognizer.save('trainner/trainner.yml')

1 ответ

Started from OpenCV 3, cv2.createLBPHFaceRecognizer() has been moved under cv2.face модуль как cv2.face.createLBPHFaceRecognizer(), AttributeError above just said opencv can't find the module.

cv2.face module is now moved to opencv_contrib модули. Вам нужно построить opencv [1] with opencv_contrib [2] from source if you can't find a suitable raspbian или же debian based binary.

Другие вопросы по тегам