Wednesday, July 31, 2013

Compiling NiSimpleViewer -- from Kinect OpenNI sample code

(This was an old article kept in draft state for about four months)

In previous post I installed the OpenNI SDK and tested some of its samples [1]. I am trying to study something from the sample code and what I've chosen now is the NiSimpleViewer example (which can be found in openni/Samples/NiSimpleViewer).

To avoid messing up the original sample code, I copied the whole directory of NiSimpleViewer and renamed it to mySimpleViewer.

The first work was to compile the source code. Of course the samples included makefiles but they were used for more general and more complicated cases. What I needed was just a simple and self-contained makefile. My first attempt was to simplify the makefile, but unfortunately it's too complicate for me to understand or even to modify it. So I wrote a simple one as the follows (I knew it's unnecessary to do so for such a simple case, but I just wanted to do a bit of exercise on writing makefiles.) :

CC = g++ 
CFLAGS = -g -Wall
LDFLAGS = -lglut -lOpenNI -I /usr/include/ni 
EXECUTABLE = mySimpleViewer


After running mySimpleViewer, the program complained that the file SamplesConfig.xml cannot be found. I checked the source code as well as the files in related directories and found the path should be changed from
In fact the relative path for the source code to find the xml file is ``../Config'' but not ``../../Config''. This was because the original Makefile putted the binaries in openni/Samples/Bin/Release/ which was one more directory deeper than my test example (thanks to my colleague's reminder).

Also, I modified some #define macros to const type. Based on my knowledge, this would be more ``c++ style''.
const XnChar* SAMPLE_XML_PATH = "../Config/SamplesConfig.xml";

const int GL_WIN_SIZE_X = 1280;
const int GL_WIN_SIZE_Y = 1024;

const unsigned int DISPLAY_MODE_OVERLAY = 1;
const unsigned int DISPLAY_MODE_DEPTH = 2;
const unsigned int DISPLAY_MODE_IMAGE = 3;
[1] Test Kinect in Ubuntu 12.04


  1. Hi Thk,

    i did the same as you, but i got an error message.
    I want to modify the sample code but i can´t compile them.
    Maybe you can help me with this.

    Bye Andreas

  2. For restarting network-manager to solve "Networking disabled"

    you open up the terminal and type in these commands

    service network-manager stop
    rm /var/lib/NetworkManager/NetworkManager.state
    service network-manager start