Tuesday, May 8, 2012

Tutorial: Using OpenNI on Android + Tegra 3 + Kinect

OpenNI C++ Wrapper for Android:

OpenNI Binary (Kinect only):


CPU usage and FPS:
  • PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
  • 12539  2  60% R    14 532164K  65048K  fg app_39   com.nvidia.devtech.multi
  • I/Render Loop:(12539): Display loop 0.014692 (s) per frame --> over 60fps for rendering, the capture loop is threaded.

Source Code Preview: :) 
#include <xnopenni.h>
#include <xnlog.h>
#include <xncppwrapper.h>
#include <xnfpscalculator.h>
#include <xnos.h>
#include <math.h>
#include "common.h"

// Defines
#define SAMPLE_XML_PATH "/data/ni/SamplesConfig.xml"

using namespace xn;
using namespace std;

class OpenniWrapper {

 int start();
 void release();
 bool isReady();
 //the raw rgb
 void getRGB(unsigned char *rgb_buffer);
 //the raw depth image
 void getDepthDataShort(unsigned short *depth_buffer);
 //the rgbd (D = depth value and it is compressed and shifted). See documentation
 void getRGBD(unsigned char *rgbd_buffer);

 //memory for the OpenNI data
 Context g_context;
 ScriptNode g_scriptNode;
 //the depth map and color image
 DepthGenerator g_depth;
 ImageGenerator g_image;
 DepthMetaData g_depthMD;
 ImageMetaData g_imageMD;
 int width, height;
 //local storage for the depth and rgb
 unsigned char *rgbImage;
 unsigned short *pDepth;

 float depthLookUpFloat[2048];
 float depthLookUpInt[2048];
 char buf[1024];

 //private/helper functions
 XnBool fileExists(const char *fn);
 float rawDepthToMeters(int input);

Demo Videos: