在IsAvailableChanged上,Kinect Studio的IsAvailable始终为false

时间:2016-03-02 04:04:47

标签: wpf kinect kinect-sdk

Environ:Kinect 2.0 SDK,Kinect Studio,Windows 10,WPF

e.IsAvailailable在通过Kinect Studio(https://msdn.microsoft.com/en-us/library/microsoft.kinect.kinectsensor.isavailable.aspx)开始编程时总是返回false。我认为如果它正在接收数据它将返回true。请注意,即使传感器开始不可用并且从未使IsAvailableChanged处理程序跳闸,BodyReader帧也会到达。请注意,BodyBasics-WPF SDK 2.0示例的行为方式相同。

如果获得e.IsAvailable = false,许多代码示例都会停止。如果您正在使用Kinect Studio并播放,可能是一个不好的举动。

错误?特征?缺乏文件?

针对Kinect Studio的Kinect - IsAvailable = false

enter image description here

针对物理Kinect的Kinect - IsAvailable = true

enter image description here

下面的代码和XAML ......

public partial class MainWindow : Window
{
    private KinectSensor m_kinectSensor = null;
    private BodyFrameReader m_bodyReader;
    private Body[] m_bodies = null;
    public MainWindow()
    {
        this.m_kinectSensor = KinectSensor.GetDefault();
        this.m_kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged;
        this.m_kinectSensor.Open();

        // hook the body stuff
        this.m_bodyReader = m_kinectSensor.BodyFrameSource.OpenReader();
        this.m_bodyReader.FrameArrived += BodyReader_FrameArrived;

        InitializeComponent();
        Msg("MainWindow c'tor completed");
    }

    private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
    {
        Msg(String.Format("BodyReader_FrameArrived: {0}" , e.FrameReference.RelativeTime.ToString()));
    }

    private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine( "KinectSensor_IsAvailableChanged: e.IsAvailable=" + e.IsAvailable.ToString() );
        TextBlock_StatusBar.Text = "KINECT SENSOR STATUS: " + e.IsAvailable.ToString();
    }

    private void Msg ( string s )
    {
        if (s.Length <= 0) s = "ready";
        TextBlock_Msg.Text = s;
    }
}
}

XAML

<Window x:Class="FaceNSkinWPF.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:local="clr-namespace:FaceNSkinWPF"
    mc:Ignorable="d"
    Title="MainWindow" 
    Height="600" Width="800" 
    >
<Grid Margin="10,10,10,10">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
        <Button Content="ButtonOne" Width="150" Height="30" Margin="10"/>
        <Button Content="ButtonOne" Width="150" Height="30" Margin="10"/>
        <Button Content="ButtonOne" Width="150" Height="30" Margin="10"/>
    </StackPanel>
    <Viewbox Grid.Row="1" HorizontalAlignment="Center">
        <Image Source="{Binding ImageSource}" Stretch="UniformToFill" />
    </Viewbox>
    <StackPanel Grid.Row="2" Orientation="Vertical">
        <TextBlock x:Name="TextBlock_StatusBar" Height="20" Foreground="Black" FontWeight="Bold" Text="KINECT SENSOR STATUS: unknown"/>
        <TextBlock x:Name="TextBlock_Msg" Height="20" Foreground="Blue" FontWeight="Bold" Text="ready"/>
    </StackPanel>
</Grid>

0 个答案:

没有答案