Ask Your Question
0

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

asked 2017-07-15 19:28:04 -0500

About the code below:

import cv2

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')

img = cv2.imread('2.jpg')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

Im getting the following error

Traceback (most recent call last):
File "C:\Users\henri\.p2\pool\plugins\org.python.pydev_5.8.0.201706061859\pysrc\pydevd.py", line 1557, in <module>
cv2.error: C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1681: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

Things I tried without success:

  • The whole path in the xml file im using
  • Put explicit parameters like img=something

Obs: The dtype of variable gray its already uint8

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-07-16 00:35:59 -0500

berak gravatar image

you're trying to load a cascade file here:

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')

but that failed, it did not find it. (it's not the image ..)

either copy that to where you run the script, or use an absolute path for the cascade.

edit flag offensive delete link more

Comments

1

Here is how the problem was solved

I dont know why windows did not recognized the .xml file at first, so I changed for the xml file from the opencv-master folder

It worked. Thanks for the answer berak

henrique lobato gravatar imagehenrique lobato ( 2017-07-16 11:24:31 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-07-15 19:28:04 -0500

Seen: 218 times

Last updated: Jul 16