OpenCV 4.0.0 SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

New Answer OpenCV seems to now have a directory dedicated to cascades, they are placed in data and I am seeing something like this floating around in tutorials now haar_cascade_face = cv2.CascadeClassifier('data/haarcascade/haarcascade_frontalface_default.xml') You may have to find where data is on your machine or the above my work. I have not touched this project since I finished it in early 2019. Bear in mind this only works for frontal face, if you want to use Haar's Cascade for eyes that is a separate file.

old answer Turns out I didn't need to download another file and use it because opencv comes with it this little bit of code worked

cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")

Well I was in this same problem, as @TylerStrouth mentioned this code snippet doesn't work :

cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")

because there are no haarcascades files in data directory if you have just installed opencv in a standard format of pip install opencv-python or sudo apt-get install python3-opencv

You will get an error something similar to this stackoverflow question, therein is the mentioned solution that worked for me, that is if you're using python3 then you need also to install opencv-contrib-python before running the above code snippet.

pip install opencv-contrib-python

which has full package (contains both main modules and contrib/extra modules)