0

Update: Whenever I use a third party haar classifier, I get an error. First I asked the question of why I am getting the error on eye_cascacde, but later I found I am getting errors on nose_cascade too. I used this source. Whenever I use third party classifiers I get same error:

Invalid HAAR feature (expected: 'rw.r.x + rw.r.width <= W'), where
     'rw.r.x + rw.r.width' is 37
 must be less than or equal to
     'W' is 11


I read older posts on to give absolute path to the libs and the classifiers should be copied into the current working directory. I checked both and I tried giving absolute and relative path to both then also I am getting error.

This is my project structure:

image1

Path:

eyes_cascade = cv2.CascadeClassifier(r'Cascades\third-party\frontalEyes35x16.xml')

When I try the above relative path after it detects the face, it shows error as:

cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'

line 37: image2

Why I give absolute path then also it gives error, but the error is on the declaration line.

Path:

eyes_cascade= cv2.CascadeClassifier(r'C:\Users\Neel Rayal\PycharmProjects\OpenCV\Cascades\third-party\frontalEyes35x16.xml')

Error: image2

line20 is shown in the 1st pic. If the image is not clear, the error is:

SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set [ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback

Here is the code:

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor= 1.5, minNeighbors= 5)

    for(x, y, w, h) in faces:
        roi_gray = gray[y: y+h, x: x+w]
        roi_color = frame[y: y+h, x: x+w]
        cv2.rectangle(frame,  (x,y), (x+w, y+h), (255,0 , 0, ), 3)

        eyes = eyes_cascade.detectMultiScale(roi_gray, scaleFactor= 1.5, minNeighbors= 5)
        for(ex, ey, ew, eh) in eyes:
            roi_eyes = roi_gray[ey: ey+ eh, ex: ex + ew]
            cv2.rectangle(roi_gray, (ex, ey), (ex + ew, ey + eh), (255, 255, 0), 3)
darkexodus
  • 147
  • 1
  • 14
  • This error happens because the XML config for your cascade classifier either doesn't exist, or the file is corrupted. The warning you see below this message regarding the `SourceReaderCB` is a warning and is not the reason why your code is crashing. Double check your XML file and the path to make sure they're correct. – rayryeng Jun 25 '20 at 00:20
  • @rayryeng I double checked everything. I changed the paths from relative to absolute, but nothing worked! – darkexodus Jun 25 '20 at 02:27
  • Is the file itself correct? – rayryeng Jun 25 '20 at 02:31
  • I don't know. I downloaded it from Github. It shows an error when I try to load it. – darkexodus Jun 25 '20 at 02:40
  • @rayryeng Any ideas what should I do now? I am stuck on this part for many hours! – darkexodus Jun 25 '20 at 02:59
  • I suspect you didn't download the raw file but you tried to download it from the Github preview window. Try this one: https://raw.githubusercontent.com/codingforentrepreneurs/OpenCV-Python-Series/master/src/cascades/third-party/frontalEyes35x16.xml – rayryeng Jun 25 '20 at 03:26
  • No it's not working. As soon as it detects my face it throws an error: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' – darkexodus Jun 25 '20 at 03:33
  • That means it can't find the XML file. https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale. There's nothing I can really suggest. Sorry. – rayryeng Jun 25 '20 at 03:59

0 Answers0