cv2 looking in nonexistent directory for modules
Hello, trying first program after a hello world
error: cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\objdetect\src\cascadedetect.cpp:1639: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
There is no D drive on my computer, it seems there's some default cv2 path setting and it's looking in nonexistent places. How do I change this?
Code: import numpy as np import cv2
face_cascade = cv2.CascadeClassifier('C:\Invention Work\CV\opencv\build\etc\haarcascades\haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('C:\Invention Work\CV\opencv\build\etc\haarcascades\haarcascade_eye.xml')
img = cv2.imread('test1.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) roi_gray = gray[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex,ey,ew,eh) in eyes: cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.imshow('img',img) cv2.waitKey(0) cv2.destroyAllWindows()
your cascade was not loaded (that's the error.) there seems to be no valid xml file at 'C:\Invention Work\CV\opencv\build\etc\haarcascades\haarcascade_frontalface_default.xml' . please check that.
the message might be confusing, but the "wrong" path is just the location of the code while building the python wrappers (on a different machine)
Thanks for the information about the path! There is a haarcascade_frontalface_default.xml at the specified location, however, and it appears to match the original as hosted on github.
Still haven't been able to solve it.