How to access OpenCV data root directory?

asked 2016-09-05 11:42:42 -0600

keelix gravatar image

I would like to access

/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml

from OpenCV distribution, but in a platform-independent way, e.g. in Python

os.path.join(cv2.OPENCV_DATA_DIR, "haarcascades", "haarcascade_frontalface_default.xml")

Can I? How do I get a reliable OPENCV_DATA_DIR equivalent? My question is basically the same to what this StackOverflow user is asking.

For example, Qt has QCoreApplication::libraryPaths(). The correct paths are determined at compile / install time, so it should be possible to make them available to the user.

edit retag flag offensive close merge delete

Comments

imho, this would be a nice addition !

cmake knows the IINSTALL path at compile time, it shouldn't be too difficult, to wire this into the c++ code while building opencv libs.

berak gravatar imageberak ( 2016-09-05 12:01:13 -0600 )edit

@berak What about on Windos where the lib can be installed .. anywhere?

keelix gravatar imagekeelix ( 2016-09-05 12:16:57 -0600 )edit

hmm, right. if you build opencv locally, it will have an install path too. but for the prebuild binaries, that may be invalid. hmm.

berak gravatar imageberak ( 2016-09-05 12:20:03 -0600 )edit

At install time, it could write a line into some config file that some static function then could fetch. It's still a good idea. :)

keelix gravatar imagekeelix ( 2016-09-05 12:22:00 -0600 )edit