2018年3月26日 星期一

KinectTileButton 簡化程序

Ref: Kinect SDK 1.8 ControlBasics
Windows 10 Edu x64 @ ASUS X450J

0. New WPF 範本
<!--1  Add Ref  Kinect.DLL KinectToolkit.DLL, Kinect.Toolkit.Controls.DLL -->
<!--2  Add xmlns:k 命名空間-->
<!--3  XAML 加入 KinectUserViewer/SensorChooser-->
<!--4  XAML 加入 KinectRegion-->
XAML Code ---
<Window x:Class="wk55.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:k="http://schemas.microsoft.com/kinect/2013"
        xmlns:local="clr-namespace:wk55"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <!--1  Add Ref  Kinect, Toolkit, toolkit controls-->
    <!--2  Add xmlns:k-->
    <!--3  Add KinectUserViewer/SensorChooser-->
    <!--4  Add KinectRegion-->
    <Grid>
        <Grid  Margin="200 0 200 250">
            <k:KinectUserViewer k:KinectRegion.KinectRegion="{Binding ElementName=kinectRegion}" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top" />
            <k:KinectSensorChooserUI HorizontalAlignment="Center" VerticalAlignment="Top" Name="sensorChooserUi" />
        </Grid>
        <k:KinectRegion x:Name="kinectRegion">
            <Grid x:Name="kinectRegionGrid" Margin="10,120,10,120">
                <k:KinectScrollViewer Name="scrollViewer" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
                    <WrapPanel VerticalAlignment="Center" x:Name="wrapPanel" Orientation="Vertical" k:KinectTileButton.Click="wrapPanel_Click" >
                        <!-- items for design layout.  They will be replaced at runtime. -->
                        <k:KinectTileButton Label="1"/>
                        <k:KinectTileButton Label="2"/>
                        <k:KinectTileButton Label="3"/>
                        <k:KinectTileButton Label="4"/>
                        <k:KinectTileButton Label="5"/>
                        <k:KinectTileButton Label="6"/>
                        <k:KinectTileButton Label="7"/>
                        <k:KinectTileButton Label="8"/>
                        <k:KinectTileButton Label="9"/>
                        <k:KinectTileButton Label="10"/>
                    </WrapPanel>
                </k:KinectScrollViewer>
            </Grid>
        </k:KinectRegion>
    </Grid>
</Window>

C# Code ---

namespace wk55
{
//5. Add using namespace
    using Microsoft.Kinect;
    using Microsoft.Kinect.Toolkit;
    using Microsoft.Kinect.Toolkit.Controls;
    using System.Globalization;
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
//6 Add KinectSensorChooser
        private readonly KinectSensorChooser sensorChooser;
        public MainWindow()
        {
            InitializeComponent();
//7. Create KinectSensorChooser
            this.sensorChooser = new KinectSensorChooser();
         KinectSensor.KinectSensors[0].DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
            KinectSensor.KinectSensors[0].SkeletonStream.Enable();
            this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
            this.sensorChooser.Start();
            // Bind the sensor chooser's current sensor to the KinectRegion
            var regionSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
            BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);
        }
   // 8 Add cloing event
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.sensorChooser.Stop();
        }
   // 9 Add panel click events
        private void wrapPanel_Click(object sender, RoutedEventArgs e)
        {
            var button = (KinectTileButton)e.OriginalSource;
            button.Label = "Press";
        }
    // 10 Copy KinectInteraction180_32.DLL and KinectInteraction180_64.DLL into debug folder

    }
}


沒有留言:

張貼留言