我想用Kinect v2移动一个基于关节位置的按钮

本文关键字:一个 于关节 位置 按钮 Kinect v2 移动 | 更新日期: 2023-09-27 17:50:31

我的意图是用Kinect v2跟踪关节,然后根据关节位置在Canvas中移动按钮。我的问题是按钮:他们不动,保持不动

下面是我的代码:
if (joint.JointType == JointType.SpineMid) {
    ColorSpacePoint space =
    this.kinectRegion.KinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
    Point center = new Point(space.X, space.Y);
    Point[] verticies = Polygon.CalculateVertices(buttons.Count, radius,
                                                  startingAngle, center);
    int i = 0;
    foreach (var button in buttons)
    {
        choices.Add(verticies[i], button);
        i++;
    }
    foreach (var obj in choices)
    {
        Canvas.SetLeft(obj.Value, obj.Key.X);
        Canvas.SetTop(obj.Value, obj.Key.Y);
    }
    choices.Clear();
}

按钮在主窗口中声明。Xaml文件:

<Button x:Name="button1" Panel.ZIndex="1" Height="200" Width="200" Margin="0,436,1712,444" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button2" Panel.ZIndex="1" Height="200" Width="200" Margin="927,10,785,870" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button3" Panel.ZIndex="1" Height="200" Width="200" Margin="927,849,785,31" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="button4" Panel.ZIndex="1" Height="200" Width="200" Margin="1702,436,10,444" Background="Aqua" Visibility="Hidden" RenderTransformOrigin="-1.02,0.565" />
<Button x:Name="backButton" Visibility="Visible" Grid.Column="0" Style="{StaticResource BackButtonStyle}" Click="GoBack" />

verticies包含来自按钮的点。Dictionary<Point, Button> choices = new Dictionary<Point,Button>();

我想用Kinect v2移动一个基于关节位置的按钮

为什么要再次将按钮放置到Canvas中?你可以简单地改变它们的Canvas.LeftCanvas.Top属性,它们就会被移动。