我是 Kinect 和 VS 开发的新手,我使用的是Windows Kinect Quickstart Series,但不幸的是,它适用于 Kinect SDK v1.00。
我被 KinectColorView 的使用卡住了,我无法继续(我已经用谷歌搜索了 2 天了)。我还发现了这个非常相似的问题:在 StackOverflow 上的 SDK1.5 中使用 KinectColorViewer但无法解决我的问题。我知道我很接近,但我需要帮助。
问题是:我无法让我的 KinectColorViewer 工作。
我将它添加到 XAML 设计器,但似乎我无法将它绑定到 SensorManager。这是我的 XAML 代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="KinectSetupDev.MainWindow"
Title="MainWindow" Height="768" Width="1024" Loaded="Window_Loaded_1" Closed="Window_Closed_1">
<Grid HorizontalAlignment="Left" Height="736" VerticalAlignment="Top" Width="1012" Margin="2,2,0,0">
<TextBlock x:Name="tbMessages" HorizontalAlignment="Left" Height="60" Margin="10,662,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="992"/>
<WpfViewers:KinectColorViewer x:Name="KinectColorViewer" KinectSensorManager="{Binding KinectSensorManager}" HorizontalAlignment="Left" Height="240" Margin="608,27,0,0" VerticalAlignment="Top" Width="320" BorderThickness="1" BorderBrush="Black"/>
</Grid>
</Window>
没有关于 XAML 代码的报告,除了我必须添加块
"KinectSensorManager="{Binding KinectSensorManager}"
在 KinectColorViewer 项目中通过编写它,因为我无法通过 XAML 设计器的 GUI 找到解决方法(所以我对它的可行性有些怀疑)。
这是我的代码隐藏(我几乎完全复制了它的问题:Using KinectColorViewer in SDK1.5 so I can't understand why it's not working!!)
namespace KinectSetupDev
{
public partial class MainWindow : Window
{
// Automatically finds a Kinect for you.
private readonly KinectSensorChooser sensorChooser = new KinectSensorChooser();
public KinectSensorManager KinectSensorManager01 { get; private set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
// Initialize the Kinect sensor manager.
KinectSensorManager01 = new KinectSensorManager();
KinectSensorManager01.KinectSensorChanged += this.KinectSensorChanged;
// Locate an available sensor.
sensorChooser.Start();
// Bind chooser's sensor value to the local sensor manager.
var kinectSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
BindingOperations.SetBinding(this.KinectSensorManager01, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);
}
private void Window_Closed_1(object sender, EventArgs e)
{
UninitializeKinectServices(KinectSensorManager01.KinectSensor);
}
#region Kinect Discovery & Setup
private void KinectSensorChanged(object sender, KinectSensorManagerEventArgs<KinectSensor> args)
{
if (null != args.OldValue)
UninitializeKinectServices(args.OldValue);
if (null != args.NewValue)
InitializeKinectServices(KinectSensorManager01, args.NewValue);
}
// Kinect enabled apps should customize which Kinect services it initializes here.
private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
{
// Application should enable all streams first.
kinectSensorManager.ColorStreamEnabled = true;
kinectSensorManager.DepthStreamEnabled = true;
kinectSensorManager.SkeletonStreamEnabled = true;
// Start the sensor!
try
{
sensor.Start();
sensorChooser.Kinect.ElevationAngle = 10;
tbMessages.Text = "Kinect Started";
}
catch (System.IO.IOException)
{
sensor = null;
tbMessages.Text = "Kinect Not Started" + "\r";
}
}
// Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here.
private void UninitializeKinectServices(KinectSensor sensor)
{
if (sensor != null)
{
if (sensor.IsRunning)
{
sensorChooser.Kinect.ElevationAngle = 0;
sensor.Stop();
sensor.AudioSource.Stop();
}
}
}
#endregion Kinect Discovery & Setup
}
}
我试图在构造函数中添加该行 DataContext = this;
,但它不起作用。
应用程序运行,我的 Kinect 启动,但 KinectColorViewer 不显示任何内容。
此外,谁能说出和之间的 sensor.SkeletonStream.Enable();
区别 kinectSensorManager.SkeletonStreamEnabled = true;
??