Installing OpenCV 3 on my mac (MacOS) without config an Virtual Env

Hello Hello people,

First of all, sorry to don’t be here so often. I hope that I will be back with more frequence now (and with interesting content as well).

This post is about how to install OpenCV in a Mac (specifically a Macbook but I think that works in any Mac (MacOS)) without create the virtual env.

The idea to create this post was because all the tutorials that I fould on the Internet was installing OpenCV using the concept of Virual Env. On my case, I would like to have the OpenCV on my main list of libraries, so this is why I would like to install without use the Virtual Env approach.

If you are not familiar with Virtual env, please have a look on this link. This is definitely a long (an interesting) topic that could be transformed in a post (Why not?! Maybe latter I will write about that).

Ok! So, to start the things let’s answer this question: What is OpenCV?

OpenCV (Open Source Computer Vision Library) “is an open source computer vision and machine learning software library” (OpenCV.org, not available).

As you could see I have something in mind to use computer vision + machine learning 8)

No worries, I will make sure that I will create a post when the project is done 🙂

So…. let’s stop chat and let’s show the step-by-step:

Ps: I already have installed Anaconda 5.0 on my machine (and I’m using Python 3.6).

Step 0: Install XCode from App Store (if you don’t have already installed).

Step 1: Install the Homebrew (more details about homebrew you could find here)

Open the terminal and run:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master
brew update
Step 2: Compile & Install OpenCV
Now, it is time to install the OpenCV using brew:
brew install opencv
Step 3: Update you conda and your numpy
conda update anaconda
conda update numpy 
(note that the numpy version required is 1.14)
Step 4: Add OpenCV’s to the site-package path to global site-packages
echo /usr/local/opt/opencv/lib/python3.6/site-packages >> 
/usr/local/lib/python3.6/site-packages/opencv3.pth
Step 5: Make OpenCV 3 Python symlink
cd anaconda/lib/python3.6/site-packages/
ln -s /usr/local/opt/opencv@3/lib//python3.6/site-packages/cv2.cpython-36m-darwin.so
Step 6: Test!
Basically let’s run python from the terminal and then import cv2 and
 
python
import cv2
print(cv2.__version__)
If everything wenet you, you have your OpenCV up and running 🙂
Ps: All the steps were based on the Chandel tutorial (Chandel, 2017).

References:

Chandel, S., V., 2017. Install OpenCV 3 on MacOS [ONLINE]. Available at https://www.learnopencv.com/install-opencv3-on-macos/ (Accessed 03/jun/2018).

OpenCV.org, About [ONLINE]. Available at: https://opencv.org/about.html (Accessed 03/jun/2018).