Thursday, October 21, 2010

OpenCV on Mac OS X

The easy way is to use MacPorts.
So I assume you have already installed MacPorts on your System.

In Snow Leopard you can build OpenCV 2.1.0 and above by MacPorts.
Step1: Update the MacPorts:
sudo port selfupdate
Step2: Build OpenCV:
sudo port install opencv
If you encounter problems just try installing dependencies  with +universal whenever possible.

Step3: Let your shell know about the libraries and pkgconfig. For bash just:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr
Step4: Now you can compile OpenCV files with:
 g++ -bind_at_load `pkg-config --cflags opencv` OpenCV-Sample.c -o OpenCV-Sample ` pkg-config --libs opencv`
Additional Step: If you don't like to type all of the above line every time you can make an alias and add it to you .profile file in your home directory if there is no .profile file in your home directory just create one. For that Just:
cd "to your home directory"
nano .profile
and add the following line in the file and save it:
alias gcv="g++ -bind_at_load `pkg-config --cflags opencv` `pkg-co nfig --libs opencv`"
Now just restart your Terminal and from now on you can compile the OpenCV files with the "gcv" command.

0 comments:

Post a Comment