Ask Your Question
0

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

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

henrique lobato gravatar image

updated 2020-10-24 16:02:38 -0600

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 -0600

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 -0600 )edit

Hi, I'm having the same problem. Could you tell me how you solved it? Thank you

mika gravatar imagemika ( 2018-07-14 17:37:06 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 19,450 times

Last updated: Jul 16 '17