First of all: I don't use Mac but Linux (and partially Windows), so maybe it is different. But here is how it works under Linux and since MacOs and Linux are similar in many points (since MacOs is an early FreeBSD clone) it may also work for you (no guarantee here!). Ah and before you start now following my points: Have you checked if python is properly installed at all? Try to run ipython
(the interactive python shall). If that is not the case install python first properly! Okay now my linux-opencv-install-howto ;) :
- Extract opencv-package in a folder - lets call it 'opencv'
- make a build folder in the extracted folder, let's call it 'build'
- go into that folder (
cd build
) - start ccmake by
ccmake ../
, now you get a curse-interface, select the option to build Python (I think it's called build_opencv_python - or similar - I am currently not under linix...). If you have set your options (you can also select several others like optimization stuff and so on): hit c
for configure, hit c
probably again, until it disappears (if you get any errors you have to resolve them now), hit g
for generate and quit. - run
make -j3
(that calls the make-files with 3 threads to build opencv a little bit faster ;) - run
sudo make install
(this installs opencv to the cmake-install-prefix-path, typically /usr/local
(maybe this is different under MacOS)
If you have installed Python properly beforehand everything should work fine now. If it doesn't work then try to set your PYTHONPATH (this is an environment variable) to the location where cv2.so is located. Look it up online how to set environment variables under MacOS (under linux it works by putting it in the .bashrc file like this: export PYTHONPATH=$PYTHONPATH:/your/path/to/python/stuff
). Good luck!
Trial and error I would say :D
Steven, I've been trialing and erroring non-stop for over 2 weeks, and failing every step of the way. MacPorts has given up on me (the problem seems to be a QGIS+GRASS+python native install that makes it impossible for Apple to recognize anything in /opt/local/..., and I need it). I'm going to have to drop out of a course I really need if I can't get opencv to work with the /Library python. I'm a photographer, not a Unix guy, and I obviously don't know enough to poke around blindly in Unix.
If I can manage to get this to work, I'll write it up as carefully as I can and submit it as a tutorial - from the list of posts at the right of this screen, it's obviously needed, and I'm happy to help. But, I need some help ...(more)
Okay, looking at the download page, it states that linux/mac osx use the same download link. I guess this indicates you need to follow the installation steps that are done on linux to get OpenCV and python to work.
I've installed cmake with cmake-2.8.10.2-Darwin64-universal.dmg
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/Applications/opencv-2.4.4
CMake Error: The source directory "/Users/john/Applications/opencv-2.4.4/CMAKE_INSTALL_PREFIX=/Users/john/Applications/opencv-2.4.4" does not exist.
It does exist - I was in it.
FaceTracker/REAME.txt Building the OpenCV.framework: In the main directory of the opencv distribution, you will find a shell script called 'make_frameworks.sh' that does all of the typical unixy './configure && make' stuff required to build a universal binary framework. Invoke this script from Terminal.app, wait some minutes and you are done.
There is no such script in the package OpenCV-2.4.4a.tar.bz2
...?
I have no experience in Python and building OpenCV myself, so guess my help stops here. Go through guides online, there are tons of guides explaining the installation of openCV in mac OSX.
I found heaps of guides that were for old versions, but one mentioned a cmake -G "Unix Makefiles" command that uses a CMakeLists.txt that is in the tarball. Tried it:
cmake -G "Unix Makefiles"
make
sudo make install
all kinds of directories and stuff were put in the opencv-2.4.4 directory but nothing put into Library/Frameworks/Python.framework/Versions/2.7/lib/Python2.7/site-packages where numpy & scipy are, so python can't find it.
So, what has to be moved to the python site-packages directory from the build directory so python can find it?