Tag Archives: OpenSceneGraph

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!

osgART 2.0 RC3 with OpenSceneGraph 2.9.7 or later (including 3.0.0)

Long time ago I had problems using osgART 2.0 RC3 with OpenSceneGraph 2.9.7 or later, I couldn’t get the video feed from the webcam on the background so I only used OpenSceneGraph 2.9.6. Today I found out that my osgART program could work with OpenSceneGraph 2.9.7 or later (current version 3.0.0 works too!), but as I always used 2.9.6 I didn’t know I have founded the solution to this problem!

NOTE: If you want to install OpenSceneGraph 3.0.0 in Ubuntu 11.10 or Ubuntu 12.04 you’ll have to use the patches I’ve created and uploaded to my github repository.

The key of the problem is that when you configure the video backgrounds osgART::VideoGeode you can use TEXTURE_2D or TEXTURE_RECTANGLE. If you use TEXTURE_RECTANGLE it will work on newer versions of OpenSceneGraph. You can look at line 40 of “examples/osgartsimple/osgartsimple.cpp” in osgART 2.0 RC3 source code folder:

osg::Group* createImageBackground(osg::Image* video) {
        osgART::VideoLayer* _layer = new osgART::VideoLayer();
        _layer->setSize(*video);
        osgART::VideoGeode* _geode = new osgART::VideoGeode(osgART::VideoGeode::USE_TEXTURE_2D, video);
        addTexturedQuad(*_geode,video->s(),video->t());
        _layer->addChild(_geode);
        return _layer;
}

If you installed OpenSceneGraph 2.9.7 or later and compiled osgART 2.0 RC3 as it comes in the original code, when you execute this example from “/usr/local/bin/osgartsimple” you will get this as you show the “Hiro” pattern to the camera:

If you change previous code this way:

osg::Group* createImageBackground(osg::Image* video) {
        osgART::VideoLayer* _layer = new osgART::VideoLayer();
        _layer->setSize(*video);
        osgART::VideoGeode* _geode = new osgART::VideoGeode(osgART::VideoGeode::USE_TEXTURE_RECTANGLE, video);
        addTexturedQuad(*_geode,video->s(),video->t());
        _layer->addChild(_geode);
        return _layer;
}

Then compile and install osgART 2.0 RC3 again, “/usr/local/bin/osgartsimple” will work OK.

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: