Setting up OpenCV on Mac OSX Snow Leopard

12

Posted by Noj | Posted in Uncategorized | Posted on 06-07-2010

OpenCV is this god like library written in C/C++ that is used for computer vision. It has more than 500 algorithms and many modules for doing various different computer vision tasks. I thought I might give it a go.

After quick googling I landed on http://opencv.willowgarage.com/wiki/ . Downloaded OpenCV from sourceforge.net and ran make. Gave some error that it needs cmake. I downloaded cmake and ran the installer again. It still failed giving a 200 line error that made no sense.

I then did heaps more googling. Someone suggested to do a “sudo port install opencv”. Tried installing through macports. Even that failed as openCV had dependancies on 30 different libraries. Some libraries weren’t compatible with x64 architecture. I tried installing the libraries one by one by forcing macports to find x64 versions, but that failed as well. Some libraries won’t just get along with me.

Then after 3 days of painful searching and googling and trying out every possible method out there, I came upon this website http://vislab.cs.vt.edu/~vislab/wiki/index.php?title=Vision . It had a pre-built openCV mac framework. It had a beautiful installer and it installed like a charm. Moral of story “Terminal Geeks sometimes need to learn on how to make installation process easier for those who aren’t experts  in the domain”.

Then was there was another challenge. How do you get the code to compile. After another day of rumbling and swearing at openCV. I came upon this magic line. “-arch i386″ was the key here.

g++ -O3 <filename>.cpp -arch i386 -framework OpenCV -o <filename>

Also you’ll need to change the C/C++ headers in the following form.

“cv.h” – <OpenCV/OpenCV.h>
“highgui.h” – <OpenCV/highgui.h>
“cvXXXXX.h”-<OpenCV/XXXXX.h> where XXXXX is a library like cvaux, cvcompat, cvcore e.t.c

Hope this blog post can save others time who have similar problems.

Comments (12)

Great! A few people have been asking me about how to install opencv on a mac. I have no idea, because I don’t have one… I’ll redirect them here.

Glad you found it useful.

hello,

your link e http://vislab.cs.vt.edu/~vislab/wiki/index.php?title=Vision, is with error.
Do you have the instructions to install in MAC Snow Leopard?
Thanks.

Thanks, it work!

hi, i have a problem with this line..
may i know what is “g++ -O3 .cpp -arch i386 -framework OpenCV -o “?

sorry, but im kinda a computer goon here.

This works great! Using it for my project. Thanks =]

Thanks sir!

I was trying to install the 2.3 version to no avail, but this saved me. I just need some functions for video reading, canny and hough transform, so it’s not a big deal.

I’ll bookmark this page for future recommendation.

Thanks a lot!!

Hello, Thanx for framework. It works great..
One question. Do you know how to compile OpenCV that was called using JNI? thanx
very urgent

Hi Arazz,

I haven’t compiled OpenCV with JNI, but this could probably help http://stackoverflow.com/questions/2441198/opencv-to-jni-how-to-make-it-work

Please let me know if it works.

–Noj.

[...] Setting up OpenCV on Mac OS X Snow Leopard [...]

[...] This tutorial has been suggested by Hossam Amer to get OpenCV working on Snow Leopard Source: OpenCV Mac OS X [...]

Write a comment