I'm trying to learn cv2 in python 2.7, but when I run my code, in the specific part of it:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('2015-05-27-191152.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
it returns this:
File "face_detection.py", line 11, in <module>
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: /home/arthurckl/Desktop/opencv-3.0.0-rc1/modules/objdetect/src/cascadedetect.cpp:1595: error: (-215) !empty() in function detectMultiScale
I tried to search the answer here but the best i could find is that I must be loading the face_cascade the wrong way... Any help?
The XML or file is missing or the path to it is incorrect or the create_capture path is incorrect.
The paths in the opencv sample look like this:
cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
nested_fn = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")
cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05')