• kinect sdk开发入门WPFdemo笔记


        随着2012年2月1号Kinect For Windows SDK v1版本的发布,将会有更多的人投身于Kinect for Windows的开发,本人利用官方提供的开发视频进行编写的第一个WPF demo。步骤如下:

        1.

        2.

         3.

         4.

         5.

        6.

         7.

         8.

          9.

          10.

        11.

         12.

           13.MainWindow.xaml内容:

    <Window x:Class="KinectSdkDemo.MainWindow"
    xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
    Title
    ="MainWindow" Height="350" Width="769" Loaded="Window_Loaded" Closing="Window_Closing" xmlns:my="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers">
    <Grid Height="381">
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="354*" />
    <ColumnDefinition Width="393*" />
    </Grid.ColumnDefinitions>
    <my:KinectSensorChooser HorizontalAlignment="Left" Margin="330,123,0,0" Name="kinectSensorChooser1" VerticalAlignment="Top" Width="328" Grid.ColumnSpan="2" />
    <Image Height="240" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="320" />
    <my:KinectColorViewer HorizontalAlignment="Right" Name="kinectColorViewer1" VerticalAlignment="Top" Height="240" Width="320" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" Grid.Column="1" />
    </Grid>
    </Window>

          14.后台代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Microsoft.Kinect;

    namespace KinectSdkDemo
    {
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }

    // KinectSensor _sensor;
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
    kinectSensorChooser1.KinectSensorChanged
    += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
    //if (KinectSensor.KinectSensors.Count > 0)
    //{
    // _sensor = KinectSensor.KinectSensors[0];
    //}
    //if (_sensor.Status == KinectStatus.Connected)
    //{
    // _sensor.ColorStream.Enable();
    // _sensor.DepthStream.Enable();
    // _sensor.SkeletonStream.Enable();
    // _sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(_sensor_AllFramesReady);
    // _sensor.Start();
    //}

    }

    void _sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
    /*throw new NotImplementedException();*/
    //using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
    //{
    // if (colorFrame == null)
    // {
    // return;
    // }

    // byte[] pixels = new byte[colorFrame.PixelDataLength];
    // colorFrame.CopyPixelDataTo(pixels);

    // int stride = colorFrame.Width * 4;
    // image1.Source =
    // BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96
    // , PixelFormats.Bgr32, null, pixels, stride);

    //}
    }

    void StopKinect(KinectSensor sensor)
    {
    if (sensor != null)
    {
    sensor.Stop();
    sensor.AudioSource.Stop();
    }
    }
    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    StopKinect(kinectSensorChooser1.Kinect);
    }

    void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
    KinectSensor oldSensor = (KinectSensor)e.OldValue;
    StopKinect(oldSensor);

    KinectSensor newSensor = (KinectSensor)e.NewValue;
    newSensor.ColorStream.Enable();
    newSensor.DepthStream.Enable();
    newSensor.SkeletonStream.Enable();
    // newSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(_sensor_AllFramesReady);
    try
    {
    newSensor.Start();
    }
    catch (System.IO.IOException)
    {
    kinectSensorChooser1.AppConflictOccurred();
    }

    }
    }
    }

         15.运行结果忽略.


  • 相关阅读:
    远程连接redis服务
    redis的安装以及启动
    Easyui学习之右键菜单easyui-menu
    富文本编辑器KindEditor的使用
    zookeeper启动失败解决方法
    在TortoiseSVN使用clean up
    kettle性能优化
    idea快捷键
    Spring Cloud服务网关 Zuul Filter使用
    添加路由
  • 原文地址:https://www.cnblogs.com/yemeishu/p/2336171.html
Copyright © 2020-2023  润新知