Today I will guide you to install OpenCV4 on MacOS.
Step 1: Install Xcode:
To install Xcode simply go to the Apple App Store to find the Xcode application and proceed with the installation.
After Xcode is installed, we need to accept the terms. Open Terminal and run the following command:
1 2 | $ sudo xcodebuild -license |
Accept the terms, then install the Apple Command Line (this is required), so you can install the tools below:
1 2 | $ sudo xcode-select --install |
Click install to install.
Step 2: Install Homebrew:
To install Homebrew you can use the following command via Terminal:
1 2 | $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
Next is the Homebrew update:
1 2 | $ brew update |
Next edit bash_profile with the command:
1 2 | $ nano ~/.bash_profile |
At this point we will go to edit the file bash_profile. Add the following PATH to the end of the file:
1 2 3 | # Homebrew export PATH=/usr/local/bin:$PATH |
Press Ctrl + X to exit nano. You will get a warning about whether to save the file. Remember to save. Then run the command:
1 2 | $ source ~/.bash_profile |
Step 4: Install the prerequisites with Homebrew:
Install python 3.6:
Why is python 3.6. Because python 3.7 does not support Keras even though it supports Tensorflow, it is not recommended to install python 3.7 so to avoid library usage and unexpected errors, it is not a good choice for OpenCV. The command below is to install python 3.6.5_1:
1 2 3 | $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb $ brew switch python 3.6.5_1 |
Then confirm whether python has been installed:
1 2 | $ python3 |
Result:
1 2 3 4 | Python 3.6.5 [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. |
Please confirm the fraud:
1 2 3 | $ which python3 /usr/local/bin/python3 |
if you see /usr/local/bin/python3
you are using Homebrew python (that’s what we want) and /usr/bin/python3
means you are using system python3 and you need to fix it again in your bash_profile file and source it.
Take some time to check if you use Homebrew’s python or the system.
Please install the next prerequisites
OpenCV requires a few conditions before being installed. You will install the following packages:
- Tools used to build and compile
- Library is used for I / O operations of images
- Library optimization
1 2 3 4 | $ brew install cmake pkg-config $ brew install jpeg libpng libtiff openexr $ brew install eigen tbb |
Install wget:
1 2 | $ brew install wget |
The next part will be a bit long, so I split into 2 parts.
Source: https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/