Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing haarcascades xml files #48

Closed
a-aitken opened this issue Oct 2, 2017 · 8 comments
Closed

Missing haarcascades xml files #48

a-aitken opened this issue Oct 2, 2017 · 8 comments
Labels

Comments

@a-aitken
Copy link

a-aitken commented Oct 2, 2017

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).

  • macOS Sierra 10.12.6
  • x86-64
  • opencv-python v3.3.0.10

Thanks!

@skvark
Copy link
Member

skvark commented Oct 2, 2017

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.

@a-aitken
Copy link
Author

a-aitken commented Oct 2, 2017

Great, thanks!

@skvark
Copy link
Member

skvark commented Dec 20, 2017

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)

@abitrolly
Copy link

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.

@skvark
Copy link
Member

skvark commented Dec 21, 2017

Yes, I was thinking about something like cv2.data.haarcascades which is the path to the folder which contains the haarcascade files.

@skvark
Copy link
Member

skvark commented Dec 23, 2017

The haarcascades path can be accessed now via cv2.data.haarcascades.

@skvark skvark closed this as completed Dec 23, 2017
@tsbawa61
Copy link

Can anybody tell how to set path for xml files

@Harish1901
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants