Monday, November 2, 2009

Using OpenCV with MacOS 10.6 Snow Leopard - Part II

Since I found out, that it is quite unintuitive to work with the OpenCV framework created with the script i introduced in my first post, I'll show you how to compile OpenCV 2.0 using CMake and ffmpeg for video in- and output.

I recently tested the video capability with mit Logitech QuickCam Communicate STX using the "macam" drivers. It worked like charm, but I didn't get a good framerate - but this should be a camera problem!
 
1. GET OPENCV SOURCES 

So then let's start. The first thing we need are the OpenCV source files. Just follow the previous guide and use a svn client to get the actual data.

>> svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk'


2. INSTALL FFMPEG

We also have to install the "ffmepg" which is done by using the macports. Just type

>> sudo port -v install ffmpeg

This should take a while. Meanwhile you can get acquainted with CMake. So now we have to solve a little problem. Since OpenCV tries to find the ffmpeg header files only in "/opt/local/include" we will have to copy them there to make sure that the CMake-Script will find them. I know that isn't the cleanest solution, but I couldn't think of something more "advanced", so if you have another solution feel free to post it.

So to get everything to work just search for the folders
  • libavcodec
  • libavdevice
  • libavfilter
  • libavformat
  • libavutil
Copy them to the include folder and go on with the next steps.

3. INSTALL CMAKE 

Next thing we have to do is get a copy of CMake. You can get the newest release on the projekt hompage "http://www.cmake.org/". Install it and Open the CMake-GUI.

Start the application and ook for the "Where is the source code"-line and browse to the OpenCV folder where your svn client put the data. In the following I'll call this directory OPENCV_DIR. Create a folder, say "_make" in the OPENCV_DIR and put the path into "Where to build the binaries"-line in CMake. Now hit the "Configure"-button and CMake will ask you which compiler you want to use. Just use the default one which should be XCode, if you have installed the IDE already. After configuring you will see a reed colored window with many compile-options.

In the text output you should find entries that tell you, that "libavformat - found" and and the result tabular in the ffmpeg-section should be a line that says "gentoo-style:     1". If this is the case everything worked out just fine and we can go on to configure OpenCV.

4. COFIGURING OPENCV USING CMAKE
This is something individual, but my settings should work for most of you out there - everyone who need a different setting should know what to do when reading the parameter list. So do the following:
 
Uncheck:
  • BUILD_EXAMPLES
  • BUILD_TEST
This should do the trick. Just hit "Configure" again, and everything should get white and the "Generate" button will appear. Hit it and wait. In the OPENCV_DIR/_make/ folder you should now find an XCode-Project file which you can double-click. Just compile it in Release and/or Debug-Mode. The libs will be located in  OPENCV_DIR/_make/lib/. You will have to add them to the XCode library path or copy them into the project by drag-dropping them into the Project window (worked like charm) for me.

Make sure you are in the debug mode and compile your OpenCV programm. The debug mode will work out just fine. I haven't had luck with the release mode though - XCode doesn't seem to find the libraries anymore and I have absolutely no clue why...

Sunday, October 4, 2009

Using OpenCV2.0 with MacOS 10.6 and XCode 3.2 - PART I

First of all, I'm completely new to programming under MacOS. Some times ago I'tried to develop some IPhone applications but didn't find the time to finish my tasks. With the new OpenCV-Release few days ago I decided to try to install the library on my MacMini. As a posted yesterday the compilation went just fine, but including the library into XCode wasn't as easy as I thought it would be - but after some hours of traial end error I did eventually get the system up an running.

Here is what i've done so far. First of all you should get the newest OpenCV snapshot from the svn server. This is quite simple if you've already installed an svn-client on your mac. If this isn't the case you should first of all install 'fink' and/or 'port' to get native unix applications on your system. After installing one of these packaging systems you have to install more tools. These are:
  • subversion
  • libjpeg
  • libpng
  • libtiff
To install them just open the the 'terminal' an type: 'sudo port -v install subversion libjpeg libpng libtiff' 

After all of these libraries are install you should check out the OpenCV-SVN-folder. This is really simple but takes a while. First create a folder 'OpenCV' and browse there with your terminal. Then all you have to do is type:'svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk'

Once everything was synchronized between your folder an the svn-server there should be a folder 'trunk/opencv' in your path. There you'll find a sh-skript "make_frameworks.sh" which will configure and compile the OpenCV library as private framework to work with XCode. Just type in the terminal: './make_frameworks.sh'.  


When the skript finally finishes, there should be a file in your folder with the name "OpenCV.framework". This private framework can now be easily be included into XCode.

This is as far as a will go on today. The next time I'll describe how to successfuly integrate the framework into XCode.

Saturday, October 3, 2009

OpenCV 2.0a Released!

This is my very first try to get the new OpenCV 2.0 version running on Mac OS 10.6 (Snow Leopard). While im writing the library is still compiling and I'm hoping I will get OpenCV to work with the new XCode deliverd with Snow Leopard.

I build OpenCV yesterday on a Windows machine using Visual Studio 2008 and CMake. The building process worked out just fine but there where some problems concering the test environment. When executing the "cvtest.exe" it crashes right after the "hist_backprojection" test. I read in the mailinglist that I'm not the only person with this problem, so I added a bug report. Let's wait and see where the problem is.

Despite of the failing test, the library works just fine under Windows and my own build libs. The new C++-Inteface is great and let's you code more easily than with the old ANSI-C-Style.