Instructions to install OpenCV 4 on MacOS

Tram Ho

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:

Accept the terms, then install the Apple Command Line (this is required), so you can install the tools below:

Click install to install.

Step 2: Install Homebrew:

To install Homebrew you can use the following command via Terminal:

Next is the Homebrew update:

Next edit bash_profile with the command:

At this point we will go to edit the file bash_profile. Add the following PATH to the end of the file:

Press Ctrl + X to exit nano. You will get a warning about whether to save the file. Remember to save. Then run the command:

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:

Then confirm whether python has been installed:

Result:

Please confirm the fraud:

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

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/

Share the news now

Source : Viblo