3D 控制光标



我正在制作3D图形编辑器,它将使用Kinect进行屏幕导航。
我需要制作自己的光标,它将通过 Kinect 从右手获取轴 x 和轴 y 坐标,将其转换为计算机屏幕并将光标移动到该位置。

真正的问题是,我还需要来自深度传感器的坐标来获取轴 z 上的坐标。任何帮助将不胜感激。应用程序是在C#开发的,具有官方MS Kinect SDK

例如,如果右手移动光标,您可以获取右手的坐标,将其转换为颜色坐标并将鼠标放在所需的坐标上。

首先,声明骨架数组和坐标映射器实例 私人骷髅[]骷髅; 私有坐标映射器 cm = 新的坐标映射器();

在 AllFramesReady 或 SkeletonFrameready 事件句柄中,您可以执行以下操作:

using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
 if (skeletonFrame == null)
     return;
    if (skeletons == null || skeletons.Length != skeletonFrame.SkeletonArrayLength)
    {
        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
    }
    skeletonFrame.CopySkeletonDataTo(skeletons);
    if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
        return;
    Skeleton firstTrackedSkeleton = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();
    CoordinateMapper cm = new CoordinateMapper(YourKinectSensor);
    ColorImagePoint colorPoint = cm.MapSkeletonPointToColorPoint(first.Joints[JointType.HandRight].Position, ColorImageFormat.RgbResolution640x480Fps30);
     //Here the variable colorPoint have the X and Y values that you need to position your cursor.
}

这是基础知识,对于更详细的示例,我建议您查看 sdk 附带的示例。

最新更新