Welcome To Open Ni and Kinect Hacking :D

Posted on February 1st, 2011 by alfredo

First thing how to set it up. I’ve currently done it both ways and the free kinect drivers from openkinect.com are really good in C but the wrappers in c# leave a lot to be desired but don’t despair there is hope.

Enter Open Ni an organization founded by primesense to standarized gestures while they did not release kinect drivers they did release the middleware and drivers to a very similar equipment since kinect is based of ther prime sensor reference design. Therefore someone took the driver and made it available.

First step installation I would delve into this but someone has already done it


visit this website follow instructions if you get a problem that your sensor is not being detected(normally happens in x64 systems) go into the bin folder and run the setup directly and it should fix the driver issue. Also follow the steps in order so that it does not cause you issues.

So what can we do with this there is a pretty good wrapper with the version of nite.

Basically the way it works is that you create context and pass it the path(this context contain the camera specs since the library allows for different hardware). After that you can pass it to the Camera that you are interested going to place the code below for the depth camera since it’s the one that most people are interested in.

Context c = new Context("PathToSampleCOnfigFile");
DepthGenerator gen = new DepthGenerator(c);
DepthMetaData data;

short* point = ((short*)data.DepthMapPtr.ToPointer();
for (int i = 0; i < data.YRes*data.XRes; i++) //You prolly want to multiply that ahead of time
short value = point; ///THis will be the depth point that you are looking for
//If you need x and y coords for each point they can be found by x = i % data.XRes and y = i / data.YRes

So what do you do with this it all depends to you most people are simply mapping it to a histogram and displaying for their original demos. The standard camera can be accessed the same way.

So far I highly recommend the Primesense platform over the other openkinect drivers available the one advantage that the openkinect have at the moment is that they also give you access to the microphone which at the moment is not available for kinect. Very excited about this Open Ni initiative.

Therefore a bonus piece of code that I made to be able to port code from System.Drawing.bitmap to writeablebitmap

private unsafe static void SetPixel(int column, int row, Color color, WriteableBitmap current)
int pBackBuffer = (int)current.BackBuffer;

// Find the address of the pixel to draw.
pBackBuffer += row * current.BackBufferStride;
pBackBuffer += column * 3;

int color_data = color.B << 16; // R
color_data |= color.G << 8; // G
color_data |= color.R << 0; // B
*((int*)pBackBuffer) = color_data;

private unsafe static Color GetPixel(int column, int row, WriteableBitmap current)
int pBackBuffer = (int)current.BackBuffer;

// Find the address of the pixel to draw.
pBackBuffer += row * current.BackBufferStride;
pBackBuffer += column * 3;
return Color.FromArgb(*((int*)pBackBuffer));

That’s it for today cya soon. Btw my first WP7 game the one that I showed in december is almost done and theres been quite some improvements since last time.

Tags: kinect, programming

Categories: Programming

Leave a Reply

WordPress SEO fine-tune by Meta SEO Pack from Poradnik Webmastera