2014-11-08 82 views
1

我想開發一個應用程序,將移動光標與我的手。我用我的手寫完整的代碼和移動光標,但範圍非常有限,當我向上移動手指時,光標不會相應移動。我通過使用下面的代碼獲取手形點並設置鼠標位置。如何在縱向視圖中使用Kinect移動光標?

DepthImagePoint handPt; 

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

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

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

請告訴我怎麼動鼠標正確縱向視圖

回答

1

我覺得你的問題可能是你沒有光標的位置映射到其等效上,讓你光標或將contairner您屏幕分辨率。 Kinect的圖像通常分辨率爲640x480像素,而你的屏幕顯然要大得多。我已將該行添加到您的代碼中:

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) 

其中寬度和高度是您的容器/屏幕的寬度和高度。 請讓我知道,如果這對你有用。

+0

非常感謝您的答覆,我的屏幕寬度是720和高度是1280,我想你的代碼,但它也不能正常工作。光標仍然不在我手中。它的工作更好,但仍然是它在x軸方向和y軸極端的創建問題。 – user3480644 2014-11-10 11:29:07

2

我已經這樣做了way..this爲我工作

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);