Category Archives: Computer Vision

Install OpenCV 2.4.2 with ffmpeg support in Mac OS X 10.8

In order to install OpenCV 2.4.2 with ffmpeg support we have to first install lamemp3, faac, faad and of course ffmpeg. I’ve added a new script in my installation-scripts repository in Github but I’m going to write down here installing one by one all the libraries.

Also remember that you need to install the “Command Line Tools” in order to compile from the command line if you are using Xcode 4.4 or above. Have a look at “Can’t configure with cmake in Mac OS X 10.8” before continuing the installation process.

mp3lame:

curl -L -o lame-3.99.5.tar.gz http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz/download
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
make
sudo make install
cd ..

faac (notice that only compiles for x86_64):

curl -L -o faac-1.28.tar.gz http://sourceforge.net/projects/faac/files/faac-src/faac-1.28/faac-1.28.tar.gz/download
tar xzvf faac-1.28.tar.gz
cd faac-1.28
./configure --disable-dependency-tracking CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"
make
sudo make install
cd ..

faad:

curl -L -o faad2-2.7.tar.gz http://sourceforge.net/projects/faac/files/faad2-src/faad2-2.7/faad2-2.7.tar.gz/download
tar xvzf faad2-2.7.tar.gz
cd faad2-2.7
./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
make
sudo make install
cd ..

ffmpeg:

curl -O http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.gz
tar xzvf ffmpeg-0.11.1.tar.gz
cd ffmpeg-0.11.1
./configure --enable-libmp3lame --enable-libfaac --enable-nonfree --enable-shared --enable-pic --disable-mmx --arch=x86_64
make
sudo make install
cd ..

OpenCV 2.4.2:

curl -L -o OpenCV-2.4.2.tar.bz2 http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2/download
tar xvzf OpenCV-2.4.2.tar.bz2
cd OpenCV-2.4.2

If we configure and compile OpenCV 2.4.2 as it comes we will get a linker error at about 34% of the compilation process like this:

Linking CXX shared library ../../lib/libopencv_highgui.dylib
Undefined symbols for architecture x86_64:
  "_faacEncClose", referenced from:
      _Faac_encode_close in libavcodec.a(libfaac.o)
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncEncode", referenced from:
      _Faac_encode_frame in libavcodec.a(libfaac.o)
  "_faacEncGetCurrentConfiguration", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncGetDecoderSpecificInfo", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncOpen", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncSetConfiguration", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_lame_close", referenced from:
      _mp3lame_encode_close in libavcodec.a(libmp3lame.o)
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_float", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_int", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_interleaved", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_flush", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_get_encoder_delay", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_get_framesize", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_init", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_init_params", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_VBR", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_VBR_quality", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_bWriteVbrTag", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_brate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_disable_reservoir", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_in_samplerate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_mode", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_num_channels", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_out_samplerate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_quality", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_highgui.2.4.2.dylib] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2

To solve this problem we have to change modules/highgui/CMakeLists.txt and add just before if(HAVE_FFMPEG) (on line 158) the following text:

if(APPLE)
  list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lfaac -lbz2)
endif(APPLE)

Or we could apply this patch to OpenCV 2.4.2:

--- modules/highgui/CMakeLists.txt.old  2012-07-27 15:46:52.000000000 +0200
+++ modules/highgui/CMakeLists.txt      2012-07-27 15:47:05.000000000 +0200
@@ -155,6 +155,10 @@
   list(APPEND HIGHGUI_LIBRARIES m3api)
 endif(HAVE_XIMEA)
 
+if(APPLE)
+  list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lfaac -lbz2)
+endif(APPLE)
+
 if(HAVE_FFMPEG)
   if(UNIX AND BZIP2_LIBRARIES)
     list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})

Now we can configure, compile and install it as usual. If you want to know more configuration options of cmake for OpenCV you can have a look at “Install OpenCV 2.3.1a in Mac OS X 10.6“.

mkdir build
cmake ..
make
sudo make install
cd ..

Source: http://blog.yageek.net/2012/06/compile-opencv-241-on-mac-os-x-lion.html

Can’t configure with cmake in Mac OS X 10.8 and Xcode 4.4

I just did a clean install of Mac OS X 10.8 Mountain Lion and Xcode 4.4 so when I was ready to compile (again…) OpenCV 2.4.2 I got this error executing “cmake ..”:

$ cmake ..
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/Users/enekochan/compilaciones/OpenCV-2.4.2/build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/Users/enekochan/compilaciones/OpenCV-2.4.2/build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

New versions of Xcode (4.4 and above) don’t install themselves in /Developer so I thought it could be a path issue, but the real problem is that the terminal utilities are not included in the normal install of Xcode anymore. You can install them and agree ther terms from the command line:

sudo xcode-select --install
sudo xcodebuild -license

Or download them separately from https://developer.apple.com/downloads/ (you need an Apple ID). Then look for the latest “Command Line Tools” for your system:

Install it and you will be able to compile from the terminal.

Source: http://www.cmake.org/pipermail/cmake/2009-February/027317.html

ARSlides v1.0: Augmented Reality slide presentation application

I’m glad to inform that I’ve (finally) published the code for the Augmented Reality application I’ve been working. Here you can see a small demo of it (sorry for the low quality image):

This application can show images (JPG, GIF and also transparent PNG and TGA) and 3D models (DAE, 3DS, OSG, OBJ and FBX). You just have to write down the file paths of the files you want to show in the XML configuration file of the application and then use right key to move forward and left key to move backward. It can also show text with different colors and fonts but I still have to make some changes on the code to include this ability in the XML configuration file.

I’m currently adding video (AVI, MOV, etc.) and sound (WAV, MP3, etc.) file support and have had some success in the past with it, but problems with FFMpeg made the application crash randomly. Thats why I haven’t added this to the first version. I’ve created a new branch in Github with this so you can see how it’s being coded.

You can download the source code from this Github repository. And of course you can contribute to it! I would be very glad.

It uses ARToolKit, Collada-dom, OpenSceneGraph and osgART and in case you need some help installing them in your system you can use the installation scripts I made some time ago. There are also multiple installation guides in this blog where I explain the installation process.

Collada-dom 3D models having black textures bug solution

I used to have a problem with Collada-dom 3D models textures. Some times they were not correctly applied and appeared black colored. Just like in this case:

Some time ago I found out that this was related with the locale (the language) in which the Ubuntu system was configured. I usually use my Ubuntu in english and haven’t had any problem until one person lend me a Ubuntu laptop with spanish locale. I was all the weekend trying to figure what was going on (I didn’t get any error message so I was clue less) until I noticed that difference with my working system. I told to my colleague “I know what the problem is but don’t know how to solve, and we are out of time so just install Ubuntu in english”.

Today I made the mistake of installing the spanish locale along side with the english locale in order to have the calendars first day on monday, numbers and dates in spanish way and so on. Then… textures black. So I just uninstalled the spanish locale and though all would be OK again… but no… now the program crashed every time I tried to load a Collada-dom 3D model. But hey, this time I got an error on the console:

locale::facet::_S_create_c_locale name not valid

I could start digging with this! And found out that the problem is with the boost library. Depending on the version of your boost library (I’m using 1.46, and this is supposed to be fixed on 1.48) If the locale is not set to “C” it crashes.

So a quick fix is to export a LC_ALL environment variable to value C. You can do it permanent on your system configuring it on you profile file (in you home folder) or on a terminal just before running your program (in that same terminal of course) like this:

export LC_ALL=C

I use Eclipse-CDT to develop so the easiest way to configure this environment variable only for my application is using the Debug/Run Configurations. Click on the small arrow of the Degug or Run buttons and select “Debug Configurations…” or “Run Configurations…”. The got to the “Environment” tab and add the variable:

Hope this helps you because this has been a pain in the $%! for me! And this is how you should see now the 3D model:

UPDATE: Once I changed the locales I found out that when trying to install any package with apt-get a error was telling me that my locales were not correctly set:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = (unset),
        LC_TIME = "es_ES.UTF-8",
        LC_MONETARY = "es_ES.UTF-8",
        LC_ADDRESS = "es_ES.UTF-8",
        LC_TELEPHONE = "es_ES.UTF-8",
        LC_NAME = "es_ES.UTF-8",
        LC_MEASUREMENT = "es_ES.UTF-8",
        LC_IDENTIFICATION = "es_ES.UTF-8",
        LC_NUMERIC = "es_ES.UTF-8",
        LC_PAPER = "es_ES.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory

As you can see my locales for time, monetary, address, telephone, name, measurement, identification, numeric and paper are in spanish (es_ES.UTF-8), my language is set up to english (es_US.UTF-8) and I have none set for LC_ALL. To fix this error I executed this on the terminal:

export LC_ALL=en_US.UTF-8
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

And now the error is gone because all my locale variables are en_US.UTF-8. You can verify your locales running “locale”:

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

Sources: https://svn.boost.org/trac/boost/ticket/4688
https://svn.boost.org/trac/boost/ticket/5928
http://www.becodemyfriend.com/2011/11/perl-warning-falling-back-to-the-standard-locale-%E2%80%9Cc%E2%80%9D/

Installation scripts for ARToolKit, Collada DOM, OpenSceneGraph and osgART

I’ve created some scripts and patches so installation of all this libraries will be much less painful. The patches fix the compatibility issues with Ubuntu 11.10 and 12.04 I explained in other post and some small bugs in osgART and ARToolKit (you can also add support of V4L2 to it, credits to Kameda Yoshinari for this). I still have to test those on some versions of Ubuntu but I think they work quite well and if something goes wrong they are quite self explanatory and you’ll be able to fix them (would be nice if you tell me what you changed so I can improve them for us all ;)). If you find any errors or a way to improve them don’t hesitate to comment here or in my Github repository. You can download all the files from here:

https://github.com/enekochan/installation-scripts

You should download all the files and place them in the same folder to proceed with the installation. The correct order to execute those scripts is:

  1. installARToolKit.sh
  2. installCollada.sh
  3. installOpenSceneGraph.sh
  4. installosgART.sh

Once you install all the libraries you will be able to use osgART with Collada (.dae) files as I do in this picture:

Don’t worry I’ll explain very soon (and with source code of course) how this is done.

UPDATE: You can find here the source code for this augmented reality application!

  • Page 1 of 4
  • 1
  • 2
  • 3
  • 4
  • >