-3

I learning opencv and I'm stuck on this error:

Traceback (most recent call last):

  File "/home/nicolas/Pulpit/programowanie/python/CV/opecv.py", line 10, in <module>
    faces = face_cascade.detectMultiScale(img)

error: OpenCV(4.5.5) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

I tried every possible solution from here: First the gray martix isn't empty, second the paths are good and don't toss errors, but I still don't know what is wrong... And that's my code:

import cv2 as cv 

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

face_cascade = cv2.CascadeClassifier('/home/nicolas/Pulpit/programowanie/python/CV/databases/haar_face.xml')

faces = face_cascade.detectMultiScale(gray)

for (x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

cv2.imshow('img',img)

k = cv2.waitKey(0)
if k == 27:         # wait for ESC key to exit
    cv2.destroyAllWindows()
beaker
  • 16,331
  • 3
  • 32
  • 49

1 Answers1

0

Okey guys, I made it! I'm using linux, and in paths there are no extensions, so path should be 'haar_face' not 'haar_face.xml'.

  • why would you create an XML file without a `.xml` extension? that's just confusing. no, "this is linux" is not the reason for *data* files to become unrecognizable. linux merely doesn't need `.exe` to think something's executable, but that's not the issue here. – Christoph Rackwitz Feb 08 '22 at 13:16
  • but if code is working without ".xml" in path, it seems to be the issue – Mikołaj Sala Feb 09 '22 at 10:25