Ask Your Question

Revision history [back]

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

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.