Tag Archives: cmake

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

Install osgART 2.0 RC3 with OpenSceneGraph 2.8.3 or 2.9.6 with Collada support in Ubuntu 12.04

Before installing osgART we need to install ARToolKit, collada-dom and OpenSceneGraph so look at those post before continuing with this:

Once you have installed the dependencies for osgART download osgART 2.0 RC3 code from here and uncompress it. Run the following commands:

mkdir build
cd build
cmake .. -DCMAKE_CXX_FLAGS=-fpermissive -DCMAKE_MODULE_LINKER_FLAGS=-lgstreamer-0.10 -DCMAKE_SHARED_LINKER_FLAGS=-lgstreamer-0.10
make
sudo make install

You can remove the “-DCMAKE_CXX_FLAGS=-fpermissive” option if you add the following includes in the “include/osgART/Utils” file after “#include “:

#include 
#include 

Configure the ARTOOLKIT_CONFIG variable (you should have this already configured when installing ARToolKit):

export ARTOOLKIT_CONFIG="v4l2src device=/dev/video0 use-fixed-fps=false ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24 ! identity name=artoolkit ! fakesink"

And run the example program while showing the “Hiro” pattern to the camera:

cd /usr/local/bin/
./osgartsimple

If you get this error:

Plugin '-1' unknown!
Could not initialize video plugin!

It is caused because the osgART libraries weren’t correctly copied to the library folder (“/usr/local/lib“) and/or the OSG plugins folder (“/usr/local/lib/osgPlugins-X.X.X“). Verify that a file called “libosgART.so” is in “/usr/local/lib” and that the files “osgdb_osgart.so“, “osgart_tracker_artoolkit2.so” and “osgart_video_artoolkit2.so” are in the OSG plugins folder (that should be “/usr/local/lib/osgPlugins-2.8.3” or “/usr/local/lib/osgPlugins-2.9.6” depending on the version of OSG you installed). Be aware that if you install different versions of OSG at the same time the osgART plugin may no be copied to the plugin folder of the OSG version you want. Also you may run this just in case:

sudo ldconfig /etc/ld.so.conf

If you see a black background it is caused because of a small bug in ARToolKit. It can be fixed in ARToolKit changing “ar2VideoCapNext” function on “lib/SRC/VideoGStreamer/video.c line 378 to return 0 instead of TRUE OR by changing osgART file “src/osgART/Video/ARToolKit/ARToolKitVideo.cpp” on line 310 from this:

if (0 == ar2VideoCapNext(video))

To this:

if (ar2VideoCapNext(video))

If you want to have a smoother marker detection on osgART you can change the source code on file “src/osgART/Traker/ARToolKit/SingleMarker.cpp” and uncomment the line 76 and comment the line 77. I mean changing this:

//arGetTransMatCont(markerInfo, patt_trans, patt_center, patt_width, patt_trans);
arGetTransMat(markerInfo, patt_center, patt_width, patt_trans);

To this:

arGetTransMatCont(markerInfo, patt_trans, patt_center, patt_width, patt_trans);
//arGetTransMat(markerInfo, patt_center, patt_width, patt_trans);

Sources: http://projects.springlobby.info/issues/1575
https://github.com/bitcoin/bitcoin/pull/456
https://code.ros.org/trac/opencv/ticket/1020
http://forum.openscenegraph.org/viewtopic.php?t=7755

Install OpenSceneGraph 2.9.6 with Collada support in Ubuntu 12.04

Although I usually install OpenSceneGraph 2.8.3 to work with osgART 2.0 RC3 it is also posible to use OpenSceneGraph 2.9.6 (in fact is the latests version compatible with osgART UPDATE: read this post to see how to make osgART 2.0 RC3 work with OpenSceneGraph 2.9.7 and further). You can download it using SVN:

svn checkout http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-2.9.6 OpenSceneGraph-2.9.6

The steps to install OSG 2.9.6 with Collada support in Ubuntu 12.04 are just the same as I explained before in “Install OpenSceneGraph 2.8.3 with Collada support in Ubuntu 12.04“, but you have to do some more changes on the source code because of FFMpeg. So just add those changes to the source code of OSG 2.9.6 and then do just the same as if you were installing OSG 2.8.3:

/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
- In line 276 change this:

const int bytes_decoded = avcodec_decode_audio2(m_context, reinterpret_cast(buffer), &data_size, m_packet_data, m_bytes_remaining);

To this:

#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR==52 && LIBAVCODEC_VERSION_MINOR>=32)
            AVPacket avpkt;
            av_init_packet(&avpkt);
            avpkt.data = const_cast(m_packet_data);
            avpkt.size = m_bytes_remaining;

            const int bytes_decoded = avcodec_decode_audio3(m_context, reinterpret_cast(buffer), &data_size, &avpkt);
#else
            // fallback for older versions of ffmpeg that don't have avcodec_decode_audio3.
            const int bytes_decoded = avcodec_decode_audio2(m_context, reinterpret_cast(buffer), &data_size, m_packet_data, m_bytes_remaining);
#endif

/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp

- In line 168 change this:

const int bytes_decoded = avcodec_decode_video(m_context, m_frame.get(), &frame_finished, m_packet_data, m_bytes_remaining);

To this:

#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR==52 && LIBAVCODEC_VERSION_MINOR>=32)
            AVPacket avpkt;
            av_init_packet(&avpkt);
            avpkt.data = const_cast(m_packet_data);
            avpkt.size = m_bytes_remaining;

            const int bytes_decoded = avcodec_decode_video2(m_context, m_frame.get(), &frame_finished, &avpkt);
#else
            // fallback for older versions of ffmpeg that don't have avcodec_decode_video2.
            const int bytes_decoded = avcodec_decode_video(m_context, m_frame.get(), &frame_finished, m_packet_data, m_bytes_remaining);
#endif

Sources: http://code.metager.de/source/xref/OpenSceneGraph/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp

Install OpenSceneGraph 2.8.3 with Collada support in Ubuntu 12.04

We are going to install OpenSceneGraph 2.8.3 (for now on OSG) to use it with osgART 2.0 RC3. As far as i know the last version of OSG that works with osgART is version 2.9.6 (following versions fail to draw the background video feed from the camera UPDATE: I found the solution to this error, read more in this post), but I recommend installing the 2.8.3 version. Download it from here and uncompress it.

Install those dependencies:

sudo apt-get install cmake cmake-curses-gui libopenal-dev libopenal1 libcurl4-openssl-dev libpoppler-dev libpoppler-glib-dev librsvg2-dev libgtkglext1 libgtkglext1-dev libgtkglextmm-x11-1.2-0 libgtkglextmm-x11-1.2-dev libwxgtk2.8-dev libopenthreads-dev libtiff4-dev libinventor0 inventor-dev libgif-dev libgif4 libjasper-dev libjasper1 libopenexr-dev libopenexr6 libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev libavdevice53 libavcodec53 libavformat53 libavutil51 libswscale2 gstreamer0.10-ffmpeg ffmpeg libxine-dev libquicktime-dev winff dvdrip libavbin-dev libavbin0 libavifile-0.7c2 ffmpeg-dbg ffmpeg libavcodec-dev libavfilter-dev libxine1-ffmpeg moc-ffmpeg-plugin ffmpeg-dbg gstreamer0.10-fluendo-mp3 gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly libavbin-dev libavbin0 libavfilter-dev libavifile-0.7c2 libbabl-0.0-0 libcdaudio1 libmpeg2-4 libmpcdec6 libmp3lame0 libquicktime2 libxine1 libxine1-console libxine1-ffmpeg libxine1-misc-plugins libxine1-x moc-ffmpeg-plugin moc mjpegtools ogmtools xine-ui winff dvdrip libavbin-dev libavbin0 libavifile-0.7c2 ffmpeg-dbg ffmpeg-dbg ffmpeg libavcodec-dev libavfilter-dev libxine1-ffmpeg moc-ffmpeg-plugin

Install collada-dom as I explained in “Install collada-dom library in Ubuntu 10.04, 10.11, 11.04, 11.10 and 12.04“.

Some libraries that OSG depends on have changed so we need to change some of its source:

/src/osgPlugins/curl/ReaderWriterCURL.cpp
- Remove line 24 (#include ").
/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
- Add the following include in line 2:

#include 

- Change CODEC_TYPE_AUDIO with AVMEDIA_TYPE_AUDIO on line 220.
- Change CODEC_TYPE_VIDEO with AVMEDIA_TYPE_VIDEO on line 238.
- Replace the content from lines 84 to 96 (a switch statement) with:

error_str = AVERROR(error);

/src/osgPlugins/ffmpeg/FFmpegHeaders.hpp
- Add the following define bellow “#define __STDC_CONSTANT_MACROS“:

#define FF_API_OLD_SAMPLE_FMT 0

If you want to install OSG 2.9.6 add this changes to the source code too.

Now you can go inside your OSG 2.8.3 source code folder and run:

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-D__STDC_CONSTANT_MACROS
make
sudo make install

I added “-DCMAKE_CXX_FLAGS=-D__STDC_CONSTANT_MACROS” on cmake command to fix an error with UINT64_C definition. You can add “-DBUILD_OSG_EXAMPLES=1” to compile the examples (will be installed in “/usr/local/share/OpenSceneGraph/bin/“). If you do so download OpenSceneGraph-Data files too:

sudo svn checkout http://www.openscenegraph.org/svn/osg/OpenSceneGraph-Data/tags/OpenSceneGraph-Data-2.8.0/ /usr/local/share/OpenSceneGraph/OpenSceneGraph-Data

If you want to be sure that cmake finded the libraries from Collada, execute ccmake .. and verify that Collada library options are filled correctly:

COLLADA_BOOST_FILESYSTEM_LIBRA   /usr/lib/libboost_filesystem.so              
COLLADA_BOOST_FILESYSTEM_LIBRA   COLLADA_BOOST_FILESYSTEM_LIBRARY_DEBUG-NOTFOU
COLLADA_BOOST_SYSTEM_LIBRARY     /usr/lib/libboost_system.so                  
COLLADA_BOOST_SYSTEM_LIBRARY_D   COLLADA_BOOST_SYSTEM_LIBRARY_DEBUG-NOTFOUND  
COLLADA_DOM_ROOT                 /dom                                         
COLLADA_DYNAMIC_LIBRARY          /usr/local/lib/libcollada14dom.so            
COLLADA_DYNAMIC_LIBRARY_DEBUG    COLLADA_DYNAMIC_LIBRARY_DEBUG-NOTFOUND       
COLLADA_INCLUDE_DIR              /usr/local/include/colladadom                 
COLLADA_MINIZIP_LIBRARY          /usr/local/lib/libminizip.so                 
COLLADA_MINIZIP_LIBRARY_DEBUG    COLLADA_MINIZIP_LIBRARY_DEBUG-NOTFOUND       
COLLADA_PCRECPP_LIBRARY          /usr/lib/i386-linux-gnu/libpcrecpp.so        
COLLADA_PCRECPP_LIBRARY_DEBUG    COLLADA_PCRECPP_LIBRARY_DEBUG-NOTFOUND       
COLLADA_PCRE_LIBRARY             /usr/lib/i386-linux-gnu/libpcre.so           
COLLADA_PCRE_LIBRARY_DEBUG       COLLADA_PCRE_LIBRARY_DEBUG-NOTFOUND          
COLLADA_STATIC_LIBRARY           COLLADA_STATIC_LIBRARY-NOTFOUND              
COLLADA_STATIC_LIBRARY_DEBUG     COLLADA_STATIC_LIBRARY_DEBUG-NOTFOUND 

When you finish compiling and installing OSG you should have a file called “osgdb_dae.so” in your OSG plugins folder (“/usr/local/lib/osgPlugins-2.8.3“). If you don’t have it verify you installed correctly the collada-dom library and that OSG is configured to use it.

Add the /usr/local/lib and /usr/local/lib/osgPlugins-2.8.3 library folders to the LD_LIBRARY_PATH variable on ~/.bashrc or ~/.profile:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/osgPlugins-2.8.3

If you downloaded the OpenSceneGraph-Data files add the following too:

export OSG_FILE_PATH=/usr/local/share/OpenSceneGraph/OpenSceneGraph-Data

You can test if OSG work correctly by executing one of the examples (if you compiled them of course):

/usr/local/share/OpenSceneGraph/bin/osglogo

You should see something like this:

  • Page 1 of 2
  • 1
  • 2
  • >