Simple Viewer

Back to Tutorials

2. Smooth Viewer > 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16

viewer.png
ViiM is a SDK made to facilitate programming with 3D sensors. You'll see that it really is possible to do amazing things with a 3D sensor, yet incredibly simple. In this first tutorial, lets set a simple viewer of the raw images.

Remember that in order to follow all tutorials you must have installed OpenNI's API and the 3D sensor driver. Depending on which operating system you're running and device you're using, there are specific drivers to install.

Once everything is installed, ViiM is ready to start process data and perform many low level tasks. We built these examples on OpenFrameworks, but since ViiM is operating system and graphics engine independent, it's up to you to choose which one to use. Nowadays, there is available source code for two different graphic engines, OpenFrameworks and Irrlicht (although Ogre and Unity 3D are in our future plans) but it will become very easy to port any ViiM sample to the graphic engine at your choice.

If you haven't done it yet, please download. Let's go...

Intro
If you know nothing about OpenFrameworks, first of all you should :) because it's very powerful and easy to understand how it works. Setup function is called once at beginning, most of the times to initialize stuff. Update is called when cpu is idle so you can update and process data. Draw is to obviously draw what you want. Now that you know the basics of OpenFrameworks it's time to turn your attention to ViiM. First the header file .h When we want to use ViiM's features we simply need to include ViiMIncludes.h file. In the header file line 21 is the most important one, cause it's where ViiM engine is created.  The rest of the lines are OpenFrameworks structure for a basic application and some needed variables.

And now the source file .cpp

The method addEventListener will be explained further, don't worry, let's not hurry and start from the beginning :)

Start is a very important method, since it must be called whenever you wish to start your 3D sensor. Start runs in one separate thread and it can use the raw images grabbed by the sensor or a recorded .oni file. These are video files recorded with OpenNI. We provide several .oni files, for those who don't own a 3D sensor and want to try ViiM. start is the same as start(ViiMResolution::VGA) which means the sensor will be in VGA mode (640x480@30fps). t's also possible to choose 320x240@60fps with start(ViiMResolution::QVGA) or use oni files (OpenNI video files) with start(ViiMResolution::VGA, "Sample.oni").

Here we mirror the image with the filpImage method, get the resolution of the captured video, set OpenFramework's window size according to that same resolution and load the sample description image.

On the update method we want to store the depth and color images, so we call the getDepthPixels and getColorPixels methods to get an unsigned char vector with pixel information. OpenFrameworks will do the rest for us.

Finally we draw the depth and color images printing ViiM engine frames per second with the getFPS method. And now back to line 13 and 23. ViiM has an event-based log system, which we advise you to use in each application you create (even before calling the start method!). addEventListener(ViiMLogEvent::MESSAGE, showMessage, this) will fire the showMessage method once ViiM sends a message from the log. It warns you about errors, warnings or simple informations, but we'll get to it in detail in the Events sample.

That’s it. Simple and fast. To try this example you just need to go to apps folder, ViiM_OF_Samples and select your operating system.

2. Smooth Viewer > 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16

Back to Tutorials