Python opencv错误级联检测。cpp:1639:错误:(-215)!函数detectMultiScale中的空()
我正在学习使用python进行人脸识别的教程。这就是我使用的代码Python opencv错误级联检测。cpp:1639:错误:(-215)!函数detectMultiScale中的空(),python,raspberry-pi3,opencv3.0,face-recognition,Python,Raspberry Pi3,Opencv3.0,Face Recognition,我正在学习使用python进行人脸识别的教程。这就是我使用的代码 import cv2,os import numpy as np from PIL import Image recognizer = cv2.face.createLBPHFaceRecognizer() detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml"); def getImagesAn
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行,在
面,ID=getImagesAndLabels('trainingImage')
文件“/home/pi/pythonpy/videofacedet/craft/codacus/trainer.py”,第24行,在getImagesAndLabels中
面=检测器。检测器多尺度(imageNp)
错误:/home/pi/opencv-3.1.0/modules/objdetect/src/cascadedetest.cpp:1639:error:(-215)!函数detectMultiScale中的空()
我在某个地方读到,我指向的文件夹(trainingImage)是空的,但它不是。我用教程作者使用的相同文件名格式将面部训练图像放在那里。我希望有人能帮我解决这个问题。问题解决了。我的haarcascade xml路径错误。修复了路径,并按预期工作