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:
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'
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')
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)