Installing OpenCV 2.0 on Snow Leopard

Posted by sunny on October 17, 2009

Installing OpenCV on a Mac should be fairly simple just like installing on Linux. Turns out the problem lies in the 64bit of Snow Leopard. By default Snow Leopard runs on a 64bit kernel so if you compile any program from source it will compile in 64bit mode. So what’s the big deal you can compile OpenCV in 64bit mode. Well you can but the problem is Carbon. Carbon is the the default GUI used by OpenCV on Mac. The other options are GTK+ which is used in Linux.

Checkout the OpenCV source code from the repository and create a folder called build

svn co http://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk opencv
cd opencv

User CMake to build the code

mkdir opencv/build
cd opencv/build
cmake ..
ccmake .

ccmake

Press t to toggle to advance mode and change the following variable to:

CMAKE_CXX_COMPILER=/usr/bin/g++-4.0
CMAKE_C_COMPILER=/usr/bin/gcc-4.0

Choosing gcc 4.0 made sure that the code would compile in 32bit mode since gcc 4.0 supports only 32bit and not 64bit. Next press “c” to configure followed by “g” to generate and exit. Next make and install by:

make -j8
sudo make install

scrAPI on Snow Leopard 1

Posted by sunny on September 17, 2009

So far upgrading to Snow Leopard was smooth. I had some problems with Rails with Postgresql but the solutions could easily be found.
In one of my previous assignments I used scrAPI to scrape some content from other site but this gem was giving errors on Snow Leopard. I tried to rebuild the gem by using:

sudo env ARCHFLAGS="-arch x86_64" gem pristine scrapi

The re-built ran fine but still scrAPI was giving the same errors:

/usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/scraper/reader.rb:216:in `parse_page': Scraper::Reader::HTMLParseError: Unable to load /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/scraper/../tidy/libtidy.dylib (Scraper::Reader::HTMLParseError)
from /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/scraper/base.rb:865:in `document'
from /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/scraper/base.rb:749:in `scrape'
from /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/scraper/base.rb:347:in `scrape'
from scrapitest.rb:10

(My Ruby path might be a little different, I decided to go with installing Ruby and Rubygems from source by following this tutorial)

If you read the error message it’s not so difficult to understand basically it’s looking for a library called libtidy.dylib which it can’t findĀ  at /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/tidy/libtidy.dylib. It turns out that there is only

libtidy.dll (windows)
libtidy.so (linux)

The Mac library is missing (Mac usually use libraries ending with .dylib). So now somehow you have to install libtidy and then copy the library to the path where scrAPI is looking for. This is pretty easy using MacPorts.
sudo port install tidy
MacPorts will install the library at /opt/local/lib (provided you used the default configuration of MacPorts). Now just copy libtidy.dylib from /opt/local/lib to /usr/local/lib/ruby/gems/1.8/gems/scrapi-1.2.0/lib/tidy/

That’s it scrAPI should now work fine one Snow Leopard!!!