Running OpenCV 3X is a huge pain on OS X. I have crawled through the internet and struggled a lot to make it work on my Mac. Some of the painfully long, yet didn’t work for me ways 1 and 2. Here’s my shortcut.
First off, make sure you have brew and Xcode essentials installed:
Install OpenCV 3X with the support for both Python (default) and Java, and also make sure to install OpenCV contrib project alongside, which would bring some more power to your OpenCV library:
As soon as it is installed, make sure it is accessible on the PYTHONPATH, by appending the following to
Once you have done that,
source ~/.bash_profile to reload it into the memory or simply open a new Tab on the Terminal.
Uninstall and install latest Numpy:
Cool! Now that OpenCV is successfully installed and configured, go ahead and check it out by yourself:
Alright, now it seems all OK, until it is not. If you choose to use Matplotlib which uses UI toolkits which eventually use framework version of the Python of OS X, may cause trouble. Why would you need Matplotlib? Because without it, it wouldn’t be easy for you to output the image processing changes that you are going to make. The best way, in my opinion, is to run it in a virtual environment, and that’s not going to solve the problem straight way either. Matplotlib’s FAQ helps to figure it out.
fxpy inside bin directory of the virtual environment with the following content:
In the end, forget not to change its permission
chmod +x bin/fxpy. Wait, why do we need this? Because if we don’t, we will end up with the following error message which is quite self-explanatory:
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ.
Needless to say, we have skipped that message. Lets go ahead and execute the program
Hope this will help me in the future should I reinstall OS X.