Why am i getting error?

When i write the following statement:

eye_cascade = cv2.CascadeClassifier(“D:\Courses\Coding Blocks\Machine Learning\third-party\frontalEyes35x16.xml”)

I am getting the following errors:

cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:569: error: (-2:Unspecified error) in function ‘bool _cdecl cv::HaarEvaluator::Feature::read(const class cv::FileNode &,const class cv::Size &)’

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 above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “snapchat filter.py”, line 3, in
eye_cascade = cv2.CascadeClassifier(“D:\Courses\Coding Blocks\Machine Learning\third-party\frontalEyes35x16.xml”)
SystemError: <class ‘cv2.CascadeClassifier’> returned a result with an error set

Please tell me how can i solve the problem?

This is due to the reason that later version of opencv didn’t supported the eye haarcascade file. Just write the following command on terminall

pip install opencv-python==4.0.1.23

And than your code will run fine.

Hope this cleared your doubt. :blush: