none
How to detect hand does a grip without a KinectRegion in WPF? RRS feed

  • Question

  • I want to detect grip at any time other than in a WPF control , how should I use the Managed API to do that? The SDK sample didn't show me how to use the API to write the simple program. Any help will be much appreciated.
    Wednesday, March 20, 2013 4:44 AM

Answers

  • Please see this thread for an overview of using the Kinect Interaction Stream API.

    Once you've followed those instructions and have InteractionFrameReady events being delivered to your application, you can detect a grip roughly as follows (warning, I haven't attempted to compile or run this code, but it should be close):

    private UserInfo[] userInfos = null;
    
    private void OnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
    {
        using (InteractionFrame frame = e.OpenInteractionFrame())
        {
            if (frame != null)
            {
                if (this.UserInfos == null)
                {
                    this.UserInfos = new UserInfo[frame.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;
                    }
    
                    Console.WriteLine("User " + userInfo.SkeletonTrackingId + " " + action + " their " + handSide + "hand.");
                }
            }
        }
    }
    
    This should write a line to the console output every time a user grips or releases their hand.

    John | Kinect for Windows development team

    Wednesday, March 20, 2013 11:59 PM

All replies

  • Please see this thread for an overview of using the Kinect Interaction Stream API.

    Once you've followed those instructions and have InteractionFrameReady events being delivered to your application, you can detect a grip roughly as follows (warning, I haven't attempted to compile or run this code, but it should be close):

    private UserInfo[] userInfos = null;
    
    private void OnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
    {
        using (InteractionFrame frame = e.OpenInteractionFrame())
        {
            if (frame != null)
            {
                if (this.UserInfos == null)
                {
                    this.UserInfos = new UserInfo[frame.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;
                    }
    
                    Console.WriteLine("User " + userInfo.SkeletonTrackingId + " " + action + " their " + handSide + "hand.");
                }
            }
        }
    }
    
    This should write a line to the console output every time a user grips or releases their hand.

    John | Kinect for Windows development team

    Wednesday, March 20, 2013 11:59 PM
  • Any working sample available?

    My issue is I don't understand the ControlsBasic example enough to write my own. It makes sense if I wanted to use WPF controls but I just want to know when the user does a grip or press.

    There really should be an example that receives the raw data in some kind of event. Has anyone got this to work?

    Monday, March 25, 2013 4:31 AM
  • This is really good question.
    
    Firstly, GetRawPixelData method always return null. Secondly calling  interactionStream. ProcessSkeleton method raises an exception of type InvalidCastException:
    
    "Unable to cast COM object of type 'System. __ComObject' to interface type 'Microsoft. Kinect. Toolkit. Interaction. INuiInteractionStream'. This operation failed because the QueryInterface call on the COM component for the interface with IID  failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
    I have copied KinectInteraction170_xx.dll file to the execution folder

    Sorry about posting that as a code, but there was an information that i can't post images or links before Microsoft verify my account (but this text does not conatin any links or images!)

    • Edited by mkk15 Monday, March 25, 2013 1:51 PM
    Monday, March 25, 2013 1:51 PM
  • Please see this thread for an overview of using the Kinect Interaction Stream API.


    I have posted a non working IInteractionClient on that thread (maybe something else is wrong?).

    As there are no samples of this anywhere I thought I'd put up what I've got so far. (sharing is caring...)

    Tuesday, March 26, 2013 1:28 AM
  • Hi John,

    I get this error from your code, Would you please help me to fix this error?, I tried every ways mentioned on web, I can't get this error fixed. Thank you.

    Error 1 Member 'Microsoft.Kinect.Toolkit.Interaction.InteractionFrame.UserInfoArrayLength' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\Peter\kinect_work\C#\KinectCursorController\MainWindow.xaml.cs 194 55 KinectCursorController

    if (this.userInfos == null)
    {
        this.userInfos = new UserInfo[frame.UserInfoArrayLength];
    }

    Monday, June 23, 2014 5:59 AM
  •  if (this.userInfos == null)
                    {
      this.userInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];
                    }
    Sunday, September 28, 2014 12:22 PM