Question

I'm using Kinect SDK 1.6, and I'm following the Skeleton Tracking Funamentals tutorial of Windows Kinect Quickstart Series, available here.

Even if these tutorials have been made for SDK 1.0, all was going pretty well until I followed the instructions to map the position of my hands on a custom-sized window (say 1280x720).

Dan Fernandez is using the following line of code to achieve this

    private void ScalePosition(FrameworkElement element, Joint joint)
    {
        // Convert the value to X/Y;
        Joint scaledJoint = joint.ScaleTo(1280, 720);

        ....
    }    

Well, the method ScaleTo is not a custom function, it should be provided in the Kinect SDK, but according to my editor, there's no such method. I can't locate it, and I think it might have been moved/renamed/whatever since SDK 1.0.

Just to make sure everything is in order, here is my using list, everyithing else (Skeleton tracking etc.) is working, so I really can't figure it out

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using Microsoft.Samples.Kinect.WpfViewers;

I can give further details about my code on request.

Was it helpful?

Solution

If you have the correct reference to Coding4Fun, you are actually just missing this:

using Coding4Fun.Kinect.Wpf;

at the beginning of your code.

OTHER TIPS

You can use this SDK in combination with the newest Microsoft SDK if you need ScaleTo():

http://c4fkinect.codeplex.com/

It's open source so you could just as well use their code and have your own ScaleTo().

Remember to add the correct using directive:

using Coding4Fun.Kinect.Wpf;

how to scale joints using the new Kinect SDK in C#

Scaling is part of the Coding4Fun library, available here: http://c4fkinect.codeplex.com/

Alternatively, you can write your own scaling.

Something like this will create a "hit box" of tracking for right hand, centered around the right shoulder, and will scale it to whatever the resolution of your primary screen is.

double xScaled = (rightHand.Position.X - leftShoulder.Position.X) / ((rightShoulder.Position.X - leftShoulder.Position.X) * 2) * SystemParameters.PrimaryScreenWidth;
double yScaled = (rightHand.Position.Y - head.Position.Y) / (rightHip.Position.Y - head.Position.Y) * SystemParameters.PrimaryScreenHeight;

Here is another example of a function that scales the Kinect coordinates to the screen resolution:

private static double ScaleY(Joint joint)
{
    double y = ((SystemParameters.PrimaryScreenHeight / 0.4) * -joint.Position.Y) + (SystemParameters.PrimaryScreenHeight / 2);
    return y;
}

private static void ScaleXY(Joint shoulderCenter, bool rightHand, Joint joint, out int scaledX, out int scaledY)
{
    double screenWidth = SystemParameters.PrimaryScreenWidth;

    double x = 0;
    double y = ScaleY(joint);

    // if rightHand then place shouldCenter on left of screen
    // else place shouldCenter on right of screen
    if (rightHand)
    {
        x = (joint.Position.X - shoulderCenter.Position.X) * screenWidth * 2;
    }
    else
    {
        x = screenWidth - ((shoulderCenter.Position.X - joint.Position.X) * (screenWidth * 2));
    }


    if (x < 0)
    {
        x = 0;
    }
    else if (x > screenWidth - 5)
    {
        x = screenWidth - 5;
    }

    if (y < 0)
    {
        y = 0;
    }

    scaledX = (int)x;
    scaledY = (int)y;
}
you can fix the error using this dll file


http://c4fkinect.codeplex.com/releases/view/76271
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top