繁体   English   中英

opencv错误层叠检测.cpp:1639:错误:函数detectMultiScale中的(-215)!empty()

[英]opencv error cascadedetect.cpp:1639: error: (-215) !empty() in function detectMultiScale

我正在使用python进行面部识别的教程。 所以这是我正在使用的代码

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

    recognizer = cv2.face.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('trainingImage')
    recognizer.train(faces, np.array(Ids))
    recognizer.save('trainer/trainer.yml')

这是我收到的错误消息

追溯(最近一次通话最近):文件“ /home/pi/pythonpy/videofacedet/craft/codacus/trainer.py”,第32行,面孔,Ids = getImagesAndLabels('trainingImage')文件“ / home / pi / pythonpy /videofacedet/craft/codacus/trainer.py“,第24行,位于getImagesAndLabelsfaces = detector.detectMultiScale(imageNp)错误:/home/pi/opencv-3.1.0/modules/objdetect/src/cascadedetect.cpp:1639:错误:函数detectMultiScale中的(-215)!empty()

我在某处阅读说,我指向的文件夹(trainingImage)为空,但不是。 我将脸部训练图像以教程作者使用的相同文件名格式放在此处。 我希望有人能帮助我解决这个问题。

问题解决了。 我的haarcascade xml路径错误。 修复了路径,它按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM