I am getting this error: Invalid HAAR feature (expected: 'rw.r.x + rw.r.width <= W'), where > 'rw.r.x + rw.r.width' is 22 > must be less than or equal to > 'W' is 16

asked 2020-06-24 23:05:05 -0600

neel19 gravatar image

I am trying to load an classifier, but it keep throwing error: Invalid HAAR feature (expected: 'rw.r.x + rw.r.width <= W'), where

     'rw.r.x + rw.r.width' is 22
      must be less than or equal to
     'W' is 16

The error is traced back to:

 File "C:/Users/Neel Rayal/PycharmProjects/OpenCV/Programs/moustache.py", line 13, in <module>
    eyes_cascade        = cv2.CascadeClassifier(r'C:\Users\Neel Rayal\PycharmProjects\OpenCV\Cascades\third-party\frontalEyes35x16.xml')
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

Here is my code:

import cv2
cap = cv2.VideoCapture(0)
frames_per_seconds  = 5
face_cascade        = cv2.CascadeClassifier(r'C:\Users\Neel Rayal\PycharmProjects\OpenCV\Cascades\data\haarcascade_frontalface_default.xml')
eyes_cascade        = cv2.CascadeClassifier(r'C:\Users\Neel Rayal\PycharmProjects\OpenCV\Cascades\third-party\frontalEyes35x16.xml')
nose_cascade        = cv2.CascadeClassifier(r'Cascades\third-party\Nose18x15.xml')
glasses             = cv2.imread(r"images\fun\glasses.png", -1)
mustache            = cv2.imread(r'images\fun\mustache.png',-1)



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)

#    out.write(frame)
    cv2.imshow('frame', frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

I tried absolute and relative paths. I tried raw downloading from Github. I rewrote everything. Then also I am stuck on this for the last 17 hours. I don't know what to do now.

edit retag flag offensive close merge delete

Comments

third-party\frontalEyes35x16.xml

self-trained cascade ? maybe it's broken ? did you try to replace it with a similar one ?

opencv version ?

berak gravatar imageberak ( 2020-06-25 01:32:20 -0600 )edit

@berak Nah , I downloaded it from here. Any third party library is not working. I deleted the code of eye_cascade , same error raised from nose_cascade

neel19 gravatar imageneel19 ( 2020-06-25 02:25:04 -0600 )edit

Do you have frontalEyes22x16.xml instead of frontalEyes35x16.xml?

supra56 gravatar imagesupra56 ( 2020-06-26 03:44:41 -0600 )edit
1

@supra56 Yes, But if you are suggesting me to try 22*16,XML, I already tried it. It's not working. The error in the parameter changes to something else.

neel19 gravatar imageneel19 ( 2020-06-26 12:34:47 -0600 )edit