OpenCV installation on Mac OS X. Ask Question. Up vote 16 down vote favorite. I have trawled through all of Google's and Stack Overflow's search results in order to install stupid OpenCV on my Mac and all the methods have been completely useless. In OpenCV, a video can be read either by using the feed from a camera connected to a computer or by reading a video file. The first step towards reading a video file is to create a VideoCapture object.
Active5 years, 1 month ago
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). Please don't link an article or post a method unless it has recently worked. I've already gone through tons of those. Any help would be very appreciated, I've been stuck for a couple days on this.
Details: Xcode 5, OS 10.9.4
Off Topic Edit: I realize this is a vague question but I'm not really looking for the best tool or solution. Just any one that would work.
Bren
BrenBren1,33577 gold badges2121 silver badges4444 bronze badges
closed as off-topic by Grady Player, Mark, RA., Shankar Damodaran, Robby CornelissenJul 27 '14 at 3:01
Opencv Windows Install
This question appears to be off-topic. The users who voted to close gave this specific reason:
- 'Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.' – Grady Player, Robby Cornelissen
1 Answer
The
pepper_chicopepper_chicoinfo
command was added as a suggestion so that you review the options you have when installing OpenCV. I'm using homebrew.6,63733 gold badges3535 silver badges9696 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged c++xcodemacosopencvcomputer-vision or ask your own question.
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 | $$ruby-e'$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)' |
Now that Homebrew is installed, you’ll need to update it and grab the latest package (i.e. “formula”) definitions. These formula are simply instructions on how to install a given package or library.
To update Homebrew, simply execute:
Install OpenCV 3.0 and Python 2.7+ on OSX
Step 3:
It’s bad form to use the system Python as your main interpreter. And this is especially true if you intend on using virtualenv and virtualenvwrapper (which we will be).
Let’s go ahead and use Homebrew to install our user-specific version of Python 2.7:
Install OpenCV 3.0 and Python 2.7+ on OSX
Note: This tutorial will be covering how to install and setup OpenCV 3.0 with Python 2.7. I will be covering how to install OpenCV 3.0 with Python 3+ later this month.
However, before we proceed, we need to update our PATH in our ~/.bash_profile file to indicate that we want to use Homebrew packages before any system libraries or packages. This is an absolutely critical step, so be sure not to skip it!
Open up your ~/.bash_profile file in your favorite editor (if it does not exist, create it), and append the following lines to the file:
Install OpenCV 3.0 and Python 2.7+ on OSX
2 | export PATH=/usr/local/bin:$PATH |
From there, reload your ~./bash_profile file to ensure the changes have been made:
Install OpenCV 3.0 and Python 2.7+ on OSX
As a sanity check, let’s confirm that we are using the Homebrew version of Python rather than the system one:
Install OpenCV 3.0 and Python 2.7+ on OSX
2 | /usr/local/bin/python |
If your output of which python is /usr/local/bin/python , then you are indeed using the Homebrew version of Python. And if your output is /usr/bin/python , then you are still using the system version of Python — and you need to go back and ensure that your ~/.bash_profile file is updated and reloaded correctly.
Again, this is a very important step, so be sure not to skip it!
Step 4:
Alright, time to get virtualenv and virtualenvwrapper installed and configured correctly. These packages allow us to create separate Python environments for each project we are working on. This is especially useful if you have projects that require different (or conflicting) versions of a given library.
It’s important to note that virtualenv and virtualenvwrapper are by no means required to install OpenCV 3.0 and Python 2.7+ on OSX. However, you really should be using these packages when doing Python development. It’s cleaner. Easier to maintain. And well worth the upfront effort.
Anyway, to install virtualenv and virtualenvwrapper , just execute the following command:
Install OpenCV 3.0 and Python 2.7+ on OSX
Again, we need to update our ~/.bash_profile file by appending the following two lines:
Install OpenCV 3.0 and Python 2.7+ on OSX
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 .
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 :
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 | Python2.7.8(default,Jul312014,15:41:09) [GCC4.2.1Compatible Apple LLVM5.1(clang-503.0.40)]on darwin Type'help','copyright','credits'or'license'formoreinformation. >>>cv2.__version__ |
Doesn’t that 3.0.0 look nice?
Congrats, you have now installed OpenCV 3.0 and Python 2.7+ on your OSX system!
Step 10:
After all this work, let’s give our OpenCV 3.0 install a test drive!
Most of my work in computer vision involves image search engines, or more formally, Content-based Image Retrieval. A critical step of CBIR is extracting features to quantify and abstractly represent the contents of an image.
OpenCV 3.0 has numerous updates and changes, but perhaps my personal favorite is an implementation of AKAZE features — Fast Explicit Diffusion for Accelerated Features in Nonlinear Scale Spacesby Alcantarilla et al.
Since Jurassic World was just released (and Jurassic Park is my favorite movie of all time), let’s explore how we can compute and extract AKAZE features from the following image:
Figure 4: Our Jurassic World test image that we are going to detect keypoints and extract features in using AKAZE.
Open up a new file, name it test_akaze.py , and insert the following code:
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