3

I have recently started using Microsoft Kinect for Windows SDK to program some stuff using the Kinect the device.

I am busting my ass to find a way to detect whether a certain hand is closed or opened.

I saw the Kinect for Windows Toolkit but the documentation is none existent and I can't find a way to make it work.

Does anyone knows of a simple way to detect the hand's situation? even better if it doesn't involve the need to use the Kinect toolkit.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jacob Cohen
  • 1,232
  • 3
  • 13
  • 33
  • Can you please solve this ? I am having error on the "InteractionHandType handType", it says it does not exist in the namespace.. please help me here is my question: http://stackoverflow.com/questions/28524420/the-type-or-namespace-name-interactionhandtype-could-not-be-found-kinect-sdk-1 – Faizan Feb 15 '15 at 09:13

4 Answers4

4

This is how I did it eventually:

First things first, we need a dummy class that looks somewhat like this:

public class DummyInteractionClient : IInteractionClient
{
    public InteractionInfo GetInteractionInfoAtLocation(
        int skeletonTrackingId,
        InteractionHandType handType,
        double x,
        double y)
    {
        var result = new InteractionInfo();
        result.IsGripTarget = true;
        result.IsPressTarget = true;
        result.PressAttractionPointX = 0.5;
        result.PressAttractionPointY = 0.5;
        result.PressTargetControlId = 1;

        return result;
    }
}

Then, in the main application code we need to announce about the interactions events handler like this:

this.interactionStream = new InteractionStream(args.NewSensor, new DummyInteractionClient());
                this.interactionStream.InteractionFrameReady += InteractionStreamOnInteractionFrameReady;

Finally, the code to the handler itself:

private void InteractionStreamOnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
    {
        using (InteractionFrame frame = e.OpenInteractionFrame())
        {
            if (frame != null)
            {
                if (this.userInfos == null)
                {
                    this.userInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];
                }

                frame.CopyInteractionDataTo(this.userInfos);
            }
            else
            {
                return;
            }
        }



        foreach (UserInfo userInfo in this.userInfos)
        {
            foreach (InteractionHandPointer handPointer in userInfo.HandPointers)
            {
                string action = null;

                switch (handPointer.HandEventType)
                {
                    case InteractionHandEventType.Grip:
                        action = "gripped";
                        break;

                    case InteractionHandEventType.GripRelease:
                        action = "released";

                        break;
                }

                if (action != null)
                {
                    string handSide = "unknown";

                    switch (handPointer.HandType)
                    {
                        case InteractionHandType.Left:
                            handSide = "left";
                            break;

                        case InteractionHandType.Right:
                            handSide = "right";
                            break;
                    }

                    if (handSide == "left")
                    {
                        if (action == "released")
                        {
                            // left hand released code here
                        }
                        else
                        {
                            // left hand gripped code here
                        }
                    }
                    else
                    {
                        if (action == "released")
                        {
                            // right hand released code here
                        }
                        else
                        {
                            // right hand gripped code here
                        }
                    }
                }
            }
        }
    }
Vito Gentile
  • 13,336
  • 9
  • 61
  • 96
Jacob Cohen
  • 1,232
  • 3
  • 13
  • 33
  • ,Thanks for your answer! I tried adding your code to my project but it says my project does not contain a definition of interactionStream. I am a beginner! Can you please put the entire code in a sample .sln file and share it ? I am running kinect SDK 1.8 – Faizan Jan 25 '15 at 10:22
  • and it also gives error on the "InteractionHandType" you created in dummyclass.. even though I have included "using Microsoft.Kinect.Toolkit.Interaction;" Please somebody help~! – Faizan Jan 25 '15 at 11:58
  • See [this answer](http://stackoverflow.com/a/28524772/738017) for adding Microsoft.Kinect.Toolkit.Interaction to your project – Vito Gentile Jun 19 '15 at 15:49
2

SDK 1.7 introduces the interaction concept called "grip". You read about all the KinectInteraction concepts at the following link: http://msdn.microsoft.com/en-us/library/dn188673.aspx

The way Microsoft has implemented this is via an event from an KinectRegion. Among the KinectRegion Events are HandPointerGrip and HandPointerGripRelease, which fire at the appropriate moments. Because the event is coming from the element the hand is over you can easily take appropriate action from the event handler.

Note that a KinectRegion can be anything. The base class is a ContentControl so you can place something as simple as an image to a complex Grid layout within the region to be acted on.

You can find an example of how to use this interaction in the ControlBasics-WPF example, provided with the SDK.

UPDATE:

KinectRegion is simply a fancy ContentControl, which in turn is just a container, which can have anything put inside. Have a look at the ControlBasics-WPF example, at the Kinect for Windows CodePlex, and do a search for KinectRegion in the MainWindow.xaml file. You'll see that there are several controls inside it which are acted upon.

To see how Grip and GripRelease are implemented in this example, it is best to open the solution in Visual Studio and do a search for "grip". They way they do it is a little odd, in my opinion, but it is a clean implementation that flows very well.

Nicholas Pappas
  • 10,439
  • 12
  • 54
  • 87
  • 1
    Tried it, very limited documentation and hard to figure out how it works. Just to make sure if I understood you right, I can set anything to be "KinectRegion" ? – Jacob Cohen Sep 12 '13 at 10:07
  • Alright I managed to get the region to works. However, I cannot find a way to create the event for the grip and gripRelease. Any insights? – Jacob Cohen Sep 12 '13 at 19:23
  • I got the same problem: I could create a XAML-Element of type "KinectRegion" but i am not able to set its "Grip"-Event-Handler with something like: `...` – kiltek Dec 22 '13 at 13:50
1

For what i know Microsoft kinect for windows SDK does not best to detect open and close hands. Microsoft provides tracking of 20 body parts and does not include the fingers of the hand. You can take advantage of the kinect interactions for that in an inderect way. This tutorial shows how: http://dotneteers.net/blogs/vbandi/archive/2013/05/03/kinect-interactions-with-wpf-part-iii-demystifying-the-interaction-stream.aspx

But i think the best solution when tracking finger movements would be using OpenNI SDK.

Some of the MiddleWares of OpenNI allow finger tracking.

LucaCosta
  • 90
  • 2
  • 11
  • Unfortunately the code provided in the link does not work for me. I do not know why, the camera won't even start. – Jacob Cohen Sep 11 '13 at 13:05
  • not true anymore. with kinect sdk 1.7 it is natively supported by MS. – kiltek Dec 06 '13 at 06:09
  • I have tested the code provided by Quicksoul. For me it does work. – kiltek Dec 26 '13 at 11:03
  • 1
    The code does not work for jacob maybe because of the kinect version. Maybe Jacob use xbox 360 version . And the code in the blog tries to active the near mode which is not in xbox 360 version. I also used xbox 360 version. It did not work for me in the beginning but then i made some modifications to the code and started to work. – LucaCosta Jan 04 '14 at 17:12
  • @CodingWolf Can you please share a sample working code that detects the fist and grip release gesture? I would really appreciate if you can share it's link. Here is my email : faizan.zad@gmail.com – Faizan Feb 16 '15 at 19:52
0

You can use something like this

private void OnHandleHandMove(object source, HandPointerEventArgs args)
    {
        HandPointer ptr = args.HandPointer;
        if (ptr.HandEventType==HandEventType.Grip)
        {
           // TODO
        }
    }
Mohamed Said
  • 524
  • 7
  • 27
  • it gives error on the "InteractionHandType" you created in dummyclass.. even though I have included "using Microsoft.Kinect.Toolkit.Interaction;" Please somebody help~! – Faizan Feb 14 '15 at 19:34