1
votes

I am trying to develop an application that will move Cursor with my hand. I have written the complete code and its moving cursor with my Hand but scope is very limited, When i move my hand up, the cursor does not move accordingly. I have grab the hand points and set the mouse position by using the following code.

DepthImagePoint handPt;

Joint hand = skl.Joints[JointType.HandRight]; 

handPt = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(hand.Position, DepthImageFormat.Resolution640x480Fps30);

Mouse.setPosition(HandPt.X, handPt.Y)

Kindly tell me how move mouse correctly in Portrait view

2

2 Answers

2
votes

I have done this way..this is working for me

Joint hand = skl.Joints[JointType.HandRight]; 

CameraSpacePoint position = hand.Position;

DepthSpacePoint handPt = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);

Point relativePoint = new Point(handPt.X * (1280 / sensor.DepthFrameSource.FrameDescription.Width), handPt.Y * (720 / sensor.DepthFrameSource.FrameDescription.Height));

Mouse.setPosition(relativePoint.X, relativePoint.Y);
1
votes

I think what your problem may be is that you don't map cursor's position to its equivalent on the contairner that keeps you cursor or to your screen resolution. Kinect's image is usually in a resolution 640x480px, while your screen is obviously much bigger. I've added the line to your code:

DepthImagePoint handPt;

Joint hand = skl.Joints[JointType.HandRight]; 

handPt = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(hand.Position, DepthImageFormat.Resolution640x480Fps30);

Point mappedPoint = new Point(handPt.X * (width / sensor.DepthStream.FrameWidth), handPt.Y * (height / sensor.DepthStream.FrameHeight));

Mouse.setPosition(mappedPoint.X, mappedPoint.Y)

where width and height are width and height of your container/screen. please let me know if that worked for you.