Install Video Reader Opencv For Mac

  1. Install Opencv Mac Os
  2. Mac Install Opencv Python
  3. Install Video Reader Opencv For Mac Download

Hi David, Thanks for the reply. I tried building using step 2a It Works!!!! I am new to mac and openCV. I had trouble installing but your blog made it easy. I am looking for anyway to set up C++ OpenCV on my mac. I've found numerous articles online but they all end up giving errors of some kind. I am completely indifferent to everything but the C++ part (for example flexible on the use of Xcode).

As I mentioned last week, OpenCV 3.0 is finally here!

And if you’ve been paying attention to my Twitter stream, you may have noticed a bunch of tweets regarding installingOpenCV on OSX and Ubuntu (yep, I’ve been tweeting a lot lately, but that’s just because I’m so excited about the 3.0 release!)

To celebrate OpenCV 3.0, I have decided to perform a series of blog posts that detail how to install OpenCV 3.0 on both Python 2.7+ and Python 3+.

We’ll also be performing these Python 2.7 and Python 3+ installations on a variety of platforms including OSX, Ubuntu, and yes, the Raspberry Pi.

As I’m sure you already know, OpenCV has never been an effortless library to install. It’s not like you can let pip or easy_install to the heavy-lifting for you. In most cases you’ll be pulling down the repo, installing prerequisites, compiling by hand, and hoping that your installation goes smoothly.

With OpenCV 3.0 it doesn’t get any easier — and there are definitely some caveats and gotchas that you need to look out for (such as the opencv_contrib repository — without it, you’ll be missing out on some important features, such as SIFT, SURF, etc.)

But don’t worry, I’ve got you covered! Just keep following along with the PyImageSearch blog and I promise these tutorials will get you up and running with OpenCV 3.0 in no time.

We’ll go ahead and kick-off our OpenCV 3.0 install fest by installing v3.0 with Python 2.7+ bindings on the OSXplatform.

If you’re an Ubuntu or Raspberry Pi user, be sure to keep an eye on PyImageSearch as I’ll be posting OpenCV 3.0 install instructions for Ubuntu and the Raspberry Pi as well.

A quick note before we get started: While OpenCV 3.0 is indeed compatible with Python 3+, most computer vision developers are still using Python 2.7 (since OpenCV 2.4.X is only compatible with Python 2.7). If you’re a Python 3 user and excited to give the bindings a try — don’t worry! I’ll be covering OpenCV 3.0 and Python 3+ installation in a future tutorial. But for now, let’s stick with what we know and use Python 2.7.

UPDATE: The tutorial you are reading now covers how to install OpenCV 3.0 with Python 2.7 bindings on OSX Yosemite and below. This tutorial still works perfectly if you are using OSX Yosemite or prior, but if you want to install OpenCV on the newer El Capitan and macOS Sierra please use this freshly updated tutorial.

This is our first tutorial in our OpenCV 3.0 install-fest series. In this tutorial I’ll be detailing how to install OpenCV 3.0 and Python 2.7+ on the OSX operating system — I’ll be covering Python 3+ in a future post.

Let’s go ahead and dive into the OpenCV 3.0 and Python 2.7+ install instructions.

Step 1:

The first step we need to do is install Xcode, which is a combination of IDE and software development tools for developing applications on the OSX and iOS platforms — most of us already have Xcode installed.

But if you don’t, you’ll want to open up the App Store application and search for Xcode. From there, just click Get and Install App (and when prompted, you’ll need to enter your Apple ID username and password):

Step 2:

Now that Xcode is installed, we need to install Homebrew, which is labeled as “The missing package manager for OSX” (and they really are not joking about that one). Think of Homebrew as an (almost) equivalent of apt-get for Ubuntu.

To install Homebrew, simply head to the Homebrew website and simply copy and paste the command underneath the “Install Homebrew” section into your terminal:

Install OpenCV 3.0 and Python 2.7+ on OSX
2
source/usr/local/bin/virtualenvwrapper.sh

After updating the ~/.bash_profile file, we need to reload it:

Install OpenCV 3.0 and Python 2.7+ on OSX

At this point, both virtualenv and virtualenvwrapper are installed correctly, so we can create our cv virtual environment:

Install OpenCV 3.0 and Python 2.7+ on OSX

This command will create a new Python environment that is entirely sequestered from our system and Homebrew Python installations. The cv virtual environment is where we’ll be doing all of our computer vision development (and not to mention, compiling OpenCV 3.0 with Python 2.7+ support).

Step 5:

Now we can start installing some Python packages. We need to install NumPy since the OpenCV Python bindings represent images as multi-dimensional NumPy arrays:

Install OpenCV 3.0 and Python 2.7+ on OSX

Step 6:

Up until this point we have been mainly focusing on actually setting up and configuring our development environment to compile and install OpenCV — here is where the real work starts.

First, we’ll use brew to install the required developers tools, such as the wonderful CMake utility:

Install OpenCV 3.0 and Python 2.7+ on OSX
Install video reader opencv for mac

And here we are going to install the necessary image I/O packages. These packages allow you to load various image file formats such as JPEG, PNG, TIFF, etc.

Install OpenCV 3.0 and Python 2.7+ on OSX

And finally, let’s install libraries that are used to optimize various operations within OpenCV (if we so choose):

Install OpenCV 3.0 and Python 2.7+ on OSX

Step 7:

Alright, our system is all setup — time to compile and install OpenCV 3.0 with Python 2.7+ support.

The first thing we’ll do is change directory to our home directory, followed by pulling down OpenCV from GitHub, and checking out the 3.0.0 version:

Install OpenCV 3.0 and Python 2.7+ on OSX
2
4
6
$cmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local
-DPYTHON2_PACKAGES_PATH=~/.virtualenvs/cv/lib/python2.7/site-packages
-DPYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/bin
-DPYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers
-DINSTALL_C_EXAMPLES=ON-DINSTALL_PYTHON_EXAMPLES=ON
-DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules..

There are some very importantoptions we are supplying to CMake here, so let’s break them down:

  • CMAKE_BUILD_TYPE : This option indicates that we are building a release binary of OpenCV.
  • CMAKE_INSTALL_PREFIX : The base directory where OpenCV will be installed.
  • PYTHON2_PACKAGES_PATH : The explicit path to where our site-packages directory lives in our cv virtual environment.
  • PYTHON2_LIBRARY : Path to our Hombrew installation of Python.
  • PYTHON2_INCLUDE_DIR : The path to our Python header files for compilation.
  • INSTALL_C_EXAMPLES : Indicate that we want to install the C/C++ examples after compilation.
  • INSTALL_PYTHON_EXAMPLES : Indicate that we want to install the Python examples after complication.
  • BUILD_EXAMPLES : A flag that determines whether or not the included OpenCV examples will be compiled or not.
  • OPENCV_EXTRA_MODULES_PATH : This option is extremely important — here we supply the path to the opencv_contrib repo that we pulled down earlier, indicating that OpenCV should compile the extra modules as well.

Update (3 January 2016): In order to build OpenCV 3.1.0 , you need to set -DINSTALL_C_EXAMPLES=OFF (rather than ON ) in the cmake command. There is a bug in the OpenCV v3.1.0 CMake build script that can cause errors if you leave this switch on. Once you set this switch to off, CMake should run without a problem.

Whew, that was a lot of options.

Trust me, it’s a lot easier installing OpenCV 3.0 on Ubuntu where these options are automatically determined via CMake for us.

But when using OSX you’ll need to explicitly define the PYTHON2_PACKAGES_PATH , PYTHON2_LIBRARY , and PYTHON2_INCLUDE_DIR yourself. It’s a real pain, but if you don’t, your compile will fail.

Here’s an example of what my CMake output looks like:

Figure 2: Before compiling OpenCV 3.0 on your OSX system, make sure that cmake has picked up the correct Python interpreter, library, numpy version, and packages path.

Notice how the Python 2 Interpreter, Libraries, numpy version, and packages path have been correctly picked up.

You’ll also want to make sure that python2 is in the list of modules To be built, like this:

Figure 2: Ensuring the “python2” module is in our list of modules “To be built”.

If it python2 is not in this list, and is in the Unavailable list, then you need to go back to the CMake step and ensure that you have correctly supplied your PYTHON2_PACKAGES_PATH , PYTHON2_LIBRARY , and PYTHON2_INCLUDE_DIR .

Mac

Now that CMake has properly configured the build, we can compile OpenCV:

Install OpenCV 3.0 and Python 2.7+ on OSX

Where the 4 can be replaced with however many cores you have available on your processor. Here’s an example of OpenCV compiling on my system:

Figure 3: OpenCV 3.0 with Python 2.7+ support compiling on my system.

And assuming that OpenCV compiled without error, you can now install it on your OSX system:

Install OpenCV 3.0 and Python 2.7+ on OSX

If you get an error message related to permissions (although that really shouldn’t happen), you’ll need to run the install command as sudo :

Mac Install Opencv Python

Install OpenCV 3.0 and Python 2.7+ on OSX

Step 9:

Assuming you’ve made it this far, let’s perform a sanity check and ensure OpenCV is installed:

Install OpenCV 3.0 and Python 2.7+ on OSX
2
4
6
8
10
12
14
16
18
from__future__importprint_function
image=cv2.imread('jurassic_world.jpg')
cv2.imshow('Original',image)
# initialize the AKAZE descriptor, then detect keypoints and extract
detector=cv2.AKAZE_create()
print('keypoints: {}, descriptors: {}'.format(len(kps),descs.shape))
# draw the keypoints and show the output image
cv2.imshow('Output',image)

And then execute it via:

Install OpenCV 3.0 and Python 2.7+ on OSX