Friday, May 13, 2011

Quick Start

I've added a small quick start documentation to the CodePlex page:

http://candescentnui.codeplex.com/documentation

Quickstart

First of all you need to create an OpenNIFacade. This object is used to interact with the OpenNI Framework (www.openni.org).

var facade = new OpenNIFacade("config.xml");

A sample config xml is checked in and must specify at least one Image and one Depth Node.

How to create a cluster data source

The next step is to create a cluster data source. But first you need an DepthDataSource (actually an IDepthPointerDataSource, because it returns only the pointer to where the depth data is located in memory).

var depthDataSource = new DepthPointerDataSource(facade.GetDepthGenerator());

With this data source you can create the cluster data source:

var clusterDataSource = new ClusterDataSource(depthDataSource);

This code will use the default setting values. You can also pass in your own settings object:

var clusterDataSource = new ClusterDataSource(depthDataSource,
    new ClusterDataSourceSettings());

To get notified after new data is available, you can register the NewDataAvailable event:

clusterDataSource.NewDataAvailable +=
    new NewDataHandler<ClusterData>(clusterDataSource_NewDataAvailable);

...

void clusterDataSource_NewDataAvailable(ClusterData data)
{
    for(int index = 0;index < data.Count;index++) 
    {
        var cluster = data.Clusters[index];
        Console.WriteLine(string.Format("Cluster {0}: {1} / {2}",
            index, cluster.X, cluster.Y));
    }
}

How to create a hand data source

To create a hand data source you first need an IClusterDataSource (see previous chapter).

var clusterDataSource = ...

var handDataSource = new HandDataSource(clusterDataSource);
handDataSource.NewDataAvailable +=
    new NewDataHandler<HandCollection>(handDataSource_NewDataAvailable);

...
void handDataSource_NewDataAvailable(HandCollection data)
{
    for (int index = 0; index < data.Count; index++) 
    {
        var hand = data.Hands[index];
        Console.WriteLine(string.Format("Fingers on hand {0}: {1}",
            index, hand.FingerPointCount));
    }
}

5 comments:

  1. This is outdated, please read the page directly:
    http://candescentnui.codeplex.com/documentation

    ReplyDelete
  2. When I tried to create an application using the codes as supplied by you on codeplex.com , Cluster data was empty. I even started the clusterDataSource by using clusterDataSource.Start() but still then Cluster data was empty. Any Suggestions?

    ReplyDelete
  3. Hi Anonymous

    Yes, calling Start() is necessary.

    Have you tried to run the sample projects?

    The Cluster data will be empty if there is nothing in the depth range that is clustered (500mm - 800mm per default).

    Are you using OpenNI oder the Kinect SDK? Kinect SDK does not return any data below 850mm so the default range setting has to be changed to 850mm - 1000mm for example.

    Regards,
    Stefan

    ReplyDelete
  4. Hi Stefan,

    I am using KinectSDK for application. I have tried with varying distances but still was unable to make it work. Yes i had ran your sample projects. Needless to say, the best one in finger point tracking. Thank you.

    ReplyDelete
  5. I could have a look at the code if you send me a zip file with what you have so far to info@candescent.ch, if that's possible.

    Regards,
    Stefan

    ReplyDelete