Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

python - OpenCV 4.0.0 SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

Hello I am trying to create a facial recognition program but I have a peculiar error: here is my code:

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier("lbpcascade_frontalface.xml")
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5);

and this error is the output

SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

I have "lbpcascade_frontalface.xml" in the working directory so that shouldn't be an issue

if it helps when I enter

cv2.__version__

I get

'4.0.0'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

New Answer OpenCV seems to now have a directory dedicated to cascades, they are placed in data and I am seeing something like this floating around in tutorials now haar_cascade_face = cv2.CascadeClassifier('data/haarcascade/haarcascade_frontalface_default.xml') You may have to find where data is on your machine or the above my work. I have not touched this project since I finished it in early 2019. Bear in mind this only works for frontal face, if you want to use Haar's Cascade for eyes that is a separate file.

old answer Turns out I didn't need to download another file and use it because opencv comes with it this little bit of code worked

cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...