2
votes

Does anybody know how to use the HandPointer class of Kinect SDK 1.7?

I have been trying to make an object hand of class HandPointer and print a message to the console when the hand is Gripped without success. I am not able to create the hand object.

Here are the MSDN links for the HandPointer class and HandPointer members.

Here's an example code segment:

//First I make the HandPointer object:

HandPointer hand;

//then later I check :

if (hand.IsInGripInteraction)
  Console.WriteLine("The hand is gripped");

The error is that my HandPointer object hand is null when I run the code. Is there any initialization which needs to be run?

1
Show us your code (ideally in the form of an SSCCE) and tell us how it's failing (what it's doing and what you expect it to do).jerry
I just posted a similar answer here: stackoverflow.com/questions/17152757/…gareththegeek

1 Answers

2
votes

In C#, all classes are reference types. A reference type variable defaults to null, so you will generally need to create an instance of the class with the new keyword and assign it:

List<string> names; // starts off as null

// the following line would cause a null reference exception
// names.Add("names");

names = new List<string>(); // create an instance

// now you can safely work with it
names.Add("names");

// of course, you can also initialize when you declare
List<string> names2 = new List<string>();

names2.Add("names2");

Based on the documentation you linked, however, the HandPointer class does not have any public constructors, so you can't do this. It is essentially an abstract class. In this case, it seems you need to instead create an instance of the KinectRegion class and access its HandPointers property.

Not being familiar at all with Kinect programming, I can't offer any advice on setting up the KinectRegion; you'll have to consult the C# samples included with the SDK. The two that look most applicable to you are Controls Basics WPF-C# Sample and InteractionGallery-WPF C# Sample.