i am working with kinect 360 and windows sdk 1.8. i have an application developed in c# wpf that can move mouse cursor with hand gestures and able to click also. the problem is whenever i want to move cursor to corner i need to take a step in front of kinect to do that. but i want to scale the cursor in such way so i only have to move my hand and cursor moves to all the screen.
Here is the code i am trying
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
bool receivedData = false;
using (SkeletonFrame SFrame = e.OpenSkeletonFrame())
{
if (SFrame == null)
{
return;
}
else
{
skeletons = new Skeleton[SFrame.SkeletonArrayLength];
SFrame.CopySkeletonDataTo(skeletons);
receivedData = true;
}
}
if (receivedData)
{
Skeleton currentSkeleton = (from s in skeletons
where s.TrackingState == SkeletonTrackingState.Tracked
select s).FirstOrDefault();
if (currentSkeleton != null)
{
processing(currentSkeleton.Joints[JointType.HandRight]);
click(currentSkeleton.Joints[JointType.HandLeft], currentSkeleton.Joints[JointType.Head]);
}
}
}
private void processing(Joint handright)
{
Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
vector.X = ScaleVector(1600, handright.Position.X);
vector.Y = ScaleVector(900, -handright.Position.Y);
vector.Z = handright.Position.Z;
handright.Position = vector;
zAxis = handright.Position.Z;
leftofscreen = Convert.ToInt32(handright.Position.X);
topofscreen = Convert.ToInt32(handright.Position.Y);
SetCursorPos(leftofscreen, topofscreen);
}
private void click(Joint handleft, Joint head)
{
if (handleft.Position.Y > head.Position.Y)
{
mouse_event(LEFTDOWN, leftofscreen, topofscreen, 0, 0);
mouse_event(LEFTUP, leftofscreen, topofscreen, 0, 0);
}
}
private float ScaleVector(int length, float position)
{
float value = (((((float)length) / 1f) / 2f) * position) + (length / 2);
if (value > length)
{
return (float)length;
}
if (value < 0f)
{
return 0f;
}
return value;
}
i have tried this kinect for c# dev and similar to youtube video code but since in this tutorial he is using sdk 1.0 and some methods are absolute so i am unable to track my hands can someone help me how i can scale my hand movement with cursor properly so i can move cursor to all the screen with a slight movement of my hand?