我正在尝试在使用 Kinect for windows (sdk 1.5) 的项目中使用 KinectColorViewer。在 kinect explorer 示例中,KinectColorViewer 组件具有绑定的 KinectSensorManager 组件。在 xaml 文件中,我们有:
<kt:KinectColorViewer x:Name="ColorViewer" KinectSensorManager="{Binding KinectSensorManager}" CollectFrameRate="True" RetainImageOnSensorChange="True" />
在其他项目中重现相同的概念时遇到很多麻烦。我使用过 Microsoft.Kinect.Toolkit 的 KinectSensorChooser、KinectSensorChooserUI 和 Mirosoft.Sampels.Kinect.wpfviewers KinectColorViewer。尝试将 colorViewer 的 KinectSensorManager 绑定到 UI 元素并跟随。
<my:KinectColorViewer Width="200" Height="200" HorizontalAlignment="Left" Margin="198,12,0,0" Name="kinectColorViewer1" VerticalAlignment="Top" KinectSensorManager="{Binding ElementName=kinectSensorChooserUI1, Path=KinectSensorChooser.Kinect}" />
两次尝试均未成功。有人用新的 SDK 使用过 ColorViwer、DepthViwer 和 SkeletonViewer 吗?认为我们会很棒...
为了绑定 KinectSensorManager,我在后端添加了以下代码:
public partial class MainWindow : Window
{
public KinectSensorManager KinectSensorManager { get; set;}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
KinectSensorManager = new KinectSensorManager();
KinectSensorManager.KinectSensorChanged += new EventHandler<KinectSensorManagerEventArgs<KinectSensor>>(KinectSensorManager_KinectSensorChanged);
// Look through all sensors and start the first connected one.
// This requires that a Kinect is connected at the time of app startup.
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
break;
}
}
if (null != this.sensor)
{
// Turn on the skeleton stream to receive skeleton frames
this.sensor.SkeletonStream.Enable();
this.sensor.DepthStream.Enable();
this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
this.sensor.AllFramesReady += new System.EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady);
this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
// Start the sensor!
try
{
this.sensor.Start();
}
catch (IOException)
{
this.sensor = null;
}
var kinectSensorBinding = new Binding("KinectSensor") { Source = this.sensor };
BindingOperations.SetBinding(this.KinectSensorManager, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);
}
if (null == this.sensor)
{
this.statusBarText.Text = Properties.Resources.NoKinectReady;
}
}
和 Xaml 文件:
<kt:KinectColorViewer Width="191" Height="83" Grid.Column="3" KinectSensorManager="{Binding KinectSensorManager}" HorizontalAlignment="Left" Margin="17,236,0,0" Name="kinectColorViewer1" VerticalAlignment="Top" />
但我仍然没有得到任何颜色流。