如何使用kinect将光标移动到屏幕角落?

How to move cursor to screen corners using kinect?

我正在使用 kinect 360 和 windows sdk 1.8。我有一个用 c# wpf 开发的应用程序,它可以用手势移动鼠标光标,也可以单击。 问题是每当我想将光标移动到角落时,我需要在 kinect 前面迈出一步才能做到这一点。 但我想以这种方式缩放光标,所以我只需要移动我的手,光标就会移动到所有屏幕。

这是我正在尝试的代码

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

我试过这个 kinect for c# dev and similar to youtube video code 但是因为在本教程中他使用的是 sdk 1.0 并且一些方法是绝对的所以我无法追踪我的手 有人可以帮助我如何使用光标正确缩放我的手部移动,以便我可以通过手的轻微移动将光标移动到所有屏幕吗?

这里是Kinect sdk v2中的项目解决方案 https://github.com/bingcheng45/Kinect-v2-Hovering-Example

假设您已经添加了 using Microsoft.Kinect 引用

Basically first you add this section into the MainWindow.xaml

<k:KinectRegion x:Name="kinectRegion">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" Margin="10 0 10 20">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>


                <k:KinectUserViewer Grid.Column="1" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top" />
                <TextBlock Grid.Column="1" HorizontalAlignment="Right" Margin="0 0 -1 0" VerticalAlignment="Bottom"  FontSize="18">Controls Basics</TextBlock>
            </Grid>

            <ContentControl Grid.Row="1" x:Name="navigationRegion">
                <Grid x:Name="kinectRegionGrid" Margin="10,20,10,20">
                    <Button x:Name="btnCenter" Content="CLICK HERE" HorizontalAlignment="Left" Margin="174,48,0,0" Style="{StaticResource 
                        FrameSelectorButtonStyle}" VerticalAlignment="Top" Width="158" Height="76"  MouseLeave="btnCenter_MouseLeave" Click="btnCenter_Click" MouseEnter="btnCenter_MouseEnter" Background="#FFC9C9C9" TouchEnter="btnCenter_TouchEnter"/>
                    <Label x:Name="lbtext" Content="Label" HorizontalAlignment="Left" Margin="51,31,0,0" VerticalAlignment="Top"/>

                </Grid>
            </ContentControl>
        </Grid>
    </k:KinectRegion>

然后只需在您的 Mainwindow.Xaml.cs 中添加这行代码即可!

public MainWindow()
        {
            InitializeComponent();

            //hovering start
            KinectRegion.SetKinectRegion(this, kinectRegion);

            App app = ((App)Application.Current);
            app.KinectRegion = kinectRegion;

            // Use the default sensor
            this.kinectRegion.KinectSensor = KinectSensor.GetDefault();
            //hovering end
        }

干杯!