Unable to open the haarcascade file in opencv

I tried many a time but it showing error everytime please help…here is where the error is occuring
“face_cascade=cv2.CascadeClassifier(“c:\Codingblocks\haarcascade_frontalface_alt (1).xml”)”

i also tried placing it in the folder and directly accessing it but still the error continues…

Sometimes error also occurs in this line
“faces=face_cascade.detectMultiScale(frame)”

Hey @nikhil_sarda, save the haarcascade file in the same folder as in your .py file and remove space and (1) from the file name and use,
“face_cascade=cv2.CascadeClassifier("haarcascade_frontalface_alt.xml”)

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

Yes , its in the same folder … i made it sure earlier and there is a space in the file name …further more i changed the file name and tried its still not working

The error its showing is

"error Traceback (most recent call last)
error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp:719: error: (-49:Unknown error code -49) Input file is invalid in function ‘cv::FileStorage::Impl::open’

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

SystemError Traceback (most recent call last)
in
2 cap=cv2.VideoCapture(0)
3 #print(face_cascade.load(“haarcascade_frontalface_alt.xml”))
----> 4 face_cascade=cv2.CascadeClassifier(“haarcascade_frontalface_alt (1).xml”)
5 #cv2.data.haarcascades(“haarcascade_frontalface_alt (1).xml”)
6 while True:

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

Hey @nikhil_sarda, try downloading the file again from the OpenCV GitHub repo.

@S18CRX0120 I am also getting the same error.
SystemError: <class ‘cv2.CascadeClassifier’> returned a result with an error set

I also tried this …but it still didn’t work and showing a different error

error Traceback (most recent call last)
in
8 if(ret==False):
9 continue
—> 10 faces=face_cascade.detectMultiScale(frame)
11 cv2.imshow(‘Video’,frame)
12 for (x,y,w,h) in faces:

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’ "

Downloading the xml file again from github worked for me.

Ok…now its done i used the file given in the webinar of codinglocks…it worked properly.

Okat that’s great, now its working !!

can u provide that link pls
I’m getting error like this
<class ‘cv2.CascadeClassifier’> returned a result with an error set

I ultimately used the file from this link as far as I remember. Also, after downloading don’t open the xml file to check its content. Directly use it in cv2 command. Here’s the link:

Can you explain how to download it?
I’m completely new to this environment

Can I know how to download those files from the provided link? I’m completely new to this)