1

I had a look at different solutions to this same problem and didnt come up with anything. I tried changing the path to the XML file. Didnt help me.

Here is the code.

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('opencv/data/haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('opencv/data/haarcascades/haarcascade_eye.xml')

img = cv2.imread('face.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

It still gives me the same error and that is

OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /home/arpit/opencv/modules/objdetect/src/cascadedetect.cpp, line 1639
Traceback (most recent call last):
  File "face.py", line 10, in <module>
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: /home/arpit/opencv/modules/objdetect/src/cascadedetect.cpp:1639: error: (-215) !empty() in function detectMultiScale

Thanks in advance :)

Arpit Joshi
  • 57
  • 1
  • 1
  • 8
  • Possible duplicate of [error: (-215) !empty() in function detectMultiScale](http://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale) – gravity Jul 05 '16 at 17:13
  • You see I did give the correct path of the _xml_ file and it still doesn't work. It worked for him in that answer. – Arpit Joshi Jul 05 '16 at 17:16
  • Given that you get the same results, my guess is that you aren't using the FQPN that accurately points to the file... have you tried putting a copy of the XML itself directly in the same root folder instead? – gravity Jul 05 '16 at 17:18
  • Tried that. Still the same error – Arpit Joshi Jul 05 '16 at 17:20

0 Answers0