OS: Mac OS X 10.9.1
Xcode: 5.0.2
OpenCV: 2.4.8.0
MacPorts: 2.2.1
cmake: 2.8.12_3
OpenCV is available from various sources. You can get it via package managers like Homebrew or MacPorts or you can build it yourself from source. It's much easier if you get it from any of the mentioned package managers but in the beginning I got some errors with that when I tried to compile tutorials. Manly because it is installed in a different location as if you build it yourself. As the OpenCV tutorials always refer to the standard path, I would recommend for beginners to build it from source so you don't have to change the code of the examples and tutorials. So, let's go.
Preparation
Install Xcode
First of all you need to have Xcode installed. Just get it from the Mac App Store. The actual Version is 5.0.2. In other tutorials you will always find that you need to install the "Command Line Tools" for Xcode. Well, maybe you needed it. But Xcode 5 comes with these tools already installed. So nothing to do here.
Before you continue, launch Xcode. When you start it the first time you have to agree to the license agreement. If you don't do this, the following will not work.
Download OpenCV
Download the OpenCV Libraries. For Mac you want to use the Unix version. You will get a .zip file - unzip it.
Just download the package from their site MacPorts-2.2.1-10.9-Mavericks
... and install it. For help, refer to the MacPorts Guide.
You can check if it was installed correctly by typing
You can check if it was installed correctly by typing
port version
in the terminal. The terminal app is in the Utilities folder in your applications.For this you want to use the previously installed MacPorts. So launch your terminal app again. Then type this in:
sudo port install cmake
This may take a while until everything is downloaded and installed. You can check your installation by typing this in your terminal:
Build OpenCV
We finally have made all the necessary preparations and are ready to build OpenCV.
1.
Copy the unpacked folder of OpenCV to your desktop und rename it to "opencv".
2.
Open your terminal and type the following in:
port installed
This will show all your installed ports. You should see cmake there.Build OpenCV
We finally have made all the necessary preparations and are ready to build OpenCV.
1.
Copy the unpacked folder of OpenCV to your desktop und rename it to "opencv".
2.
Open your terminal and type the following in:
cd Desktop/opencv
mkdir build
cd build
With these commands you go to your OpenCV folder on the desktop, create a new folder inside named "build" and enter this folder.
3.
Now we can build and install OpenCV:
That's it. You just built OpenCV from source and installed it to /usr/local.
In another post I will guide you through the process of creating your first OpenCV project in Xcode.
3.
Now we can build and install OpenCV:
cmake -G "Unix Makefiles" ..
make -j8
sudo make install
That's it. You just built OpenCV from source and installed it to /usr/local.
In another post I will guide you through the process of creating your first OpenCV project in Xcode.
Source: Tilo Mitra
Thanks for this tutorial, it helped me out. One thing to mention, you need to make sure your install is in a folder that does not have a space in the name. So no "\my folder\openCV". This last part had me for a while.
ReplyDeleteDuring the last command i got this error message : fatal error: 'opencl_kernels.hpp' file not found
ReplyDelete#include "opencl_kernels.hpp"
i got the same error :(
DeleteWhat could i do?
Thank for this tutorial. It's very helpful for me.
ReplyDeleteJust compiled on OSX 10.9.2 using homebrew and it worked just fine. Nice tutorial.
ReplyDeleteGreat tutorial, it helped a lot.
ReplyDeleteSome explanation of the commands in step 3 would be helpful.
ReplyDeletebernds-air:build bernd$ cmake -G "Unix Makefiles"
ReplyDeleteCMake Error: The source directory "/Users/bernd/opencv/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
Same error with me
DeleteYou have to write the 2 dots after : cmake -G "Unix Makefiles" ..
DeleteAny idea what causes this:
ReplyDeleteIn file included from /Users/benjamin/Desktop/opencv/modules/highgui/src/cap_ffmpeg.cpp:45:
/Users/benjamin/Desktop/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1446:5: error: use of undeclared identifier 'avformat_free_context'
avformat_free_context(oc);
^
1 error generated.
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
Same proble here, with OSX 10.10.3 :-(
DeleteWhile entering "make - j8" command on terminal it returns "No targets specified and no makefile found. Stop" . Any suggestions to overcome come this problem? Thanks in advance
ReplyDelete