Showing Error while executing the code for detection of nose

While executing the code for nose detection using opencv a error occured :

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 16
must be less than or equal to
‘W’ is 15

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\Dibakar Chaudhary\Desktop\nose.py”, line 8, in
nose = cv2.CascadeClassifier(r"C:\Users\Dibakar Chaudhary\Desktop\third-party\Nose18x15.xml")
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
[Finished in 1.8s with exit code 1]
[shell_cmd: python -u “C:\Users\Dibakar Chaudhary\Desktop\nose.py”]
[dir: C:\Users\Dibakar Chaudhary\Desktop]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\Git\cmd;C:\Users\Dibakar Chaudhary\AppData\Local\Programs\Python37;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files\nodejs;C:\Program Files (x86)\Yarn\bin;C:\Users\Dibakar Chaudhary\AppData\Local\Programs\Python\Python38\Scripts;C:\Users\Dibakar Chaudhary\AppData\Local\Programs\Python\Python38;C:\Users\Dibakar Chaudhary\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.3\bin;C:\Users\Dibakar Chaudhary\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Dibakar Chaudhary\AppData\Local\GitHubDesktop\bin;C:\Users\Dibakar Chaudhary\AppData\Roaming\npm;C:\Users\Dibakar Chaudhary\AppData\Local\Yarn\bin]

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

pip install opencv-python==4.0.1.23

And than your code will run fine.

Hope this cleared your doubt. :blush:

This is also showing error in my terminal :

ERROR: Could not find a version that satisfies the requirement opencv-python==4.0.1.23 (from versions: 3.4.8.29, 3.4.9.31, 4.1.2.30, 4.2.0.32)
ERROR: No matching distribution found for opencv-python==4.0.1.23

Use,

pip install opencv-python==3.4.9.31

sir the code is showing error

here is my code :

import numpy as np
import cv2

eye=cv2.CascadeClassifier(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\eyes.xml")
gl=cv2.imread(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\glasses.png")
img=cv2.imread(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\Before.png")

ey=eye.detectMultiScale(img,1.3,4)
x,y,w,h=ey[0]
#cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
gl1=cv2.resize(gl,(h,w))
for i in range (gl1.shape[0]):
for j in range(gl.shape[1]):
if(gl1[i,j,3]>0):
img[y+i,x+j,:]=gl1[i,j,:-1]

cv2.imshow(“Frame”,img)
cv2.waitKey(0)
cv2.destroyAllWindows()

error:

error Traceback (most recent call last)
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:

SystemError Traceback (most recent call last)
in
2 import cv2
3
----> 4 eye=cv2.CascadeClassifier(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\eyes.xml")
5 gl=cv2.imread(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\glasses.png")
6 img=cv2.imread(r"C:\Users\Dibakar Chaudhary\Desktop\Electro\Before.png")

SystemError: <class ‘cv2.CascadeClassifier’> returned a result with an error set

The error is due to the opencv version. Let me check what all options you have. Will be back to you very soon

I used
!pip3 install opencv-python==3.4.8.29

on jupyter notebook and my code was able to load both the classifiers. If error still persists try running your code on google colab with the said version.

Hope this cleared your doubt. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.