First thanks for putting this package together!
I'm trying to perform face detection by following this tutorial: http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html, however this leads to an error as the haarcascade xml files appear to be missing from the wheel:
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
print(face_cascade.empty())
img = cv2.imread(<path/to/an/image/file>)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
This should print False and then perform face detection. However, it prints True and then leads to an error:
opencv-python/opencv/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale
It looks as though the files under https://github.com/opencv/opencv/tree/master/data are missing from the wheels so I guess that adding them should fix this.
(This works as expected using the conda package).
Thanks!
Thanks for the report, I'll add them to the package in next release. I have to go first through the licenses of those files. Most of them seem to be under BSD-like license so shouldn't be a problem to include them.
Great, thanks!
I had a better look into this. That tutorial is a bit misleading since it's not very clear on where the script has to executed:
"Those XML files are stored in the opencv/data/haarcascades/ folder."
Now, even if I distribute all the XML files with this package the following line won't still work because it tries to read the XML file from the same folder where your script is executed:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
If I add those files in the package, you will have to use something like this:
haarcascades_path = os.path.dirname(cv2.__file__) + "/haarcascade_frontalface_default.xml"
face_cascade = cv2.CascadeClassifier(haarcascades_path)
Maybe add from cv2 import DATA as a helper for os.path.dirname(cv2.__file__)?
Or maybe even a constant cv2.data.haarcascade if there are not many files.
Yes, I was thinking about something like cv2.data.haarcascades which is the path to the folder which contains the haarcascade files.
The haarcascades path can be accessed now via cv2.data.haarcascades.
Can anybody tell how to set path for xml files
Hi all..I am using openCV2 with OS X Xcode....why there is no data folder in opencv framework ? to use haar cascade xml file..kindly help me out
Most helpful comment
I had a better look into this. That tutorial is a bit misleading since it's not very clear on where the script has to executed:
Now, even if I distribute all the XML files with this package the following line won't still work because it tries to read the XML file from the same folder where your script is executed:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')If I add those files in the package, you will have to use something like this: