0

KinectColorViewer を SDK 1.7 で動作させようとしていますが、うまくいきません。カメラから画像要素にピクセルを手動でコピーした場合にのみ、ビデオ画像を表示できます。

次の XAML があります。

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:k="http://schemas.microsoft.com/kinect/2013"
  xmlns:WpfViewers="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" x:Class="KinectD.Camera"
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="500"
Title="Camera">

<Grid>
    <k:KinectUserViewer k:KinectRegion.KinectRegion="{Binding ElementName=kinectRegion}" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top" />
    <k:KinectSensorChooserUI HorizontalAlignment="Center" VerticalAlignment="Top" x:Name="sensorChooserUi" />

    <k:KinectRegion x:Name="kinectRegion">
        <Grid>
            <k:KinectCircleButton Label="Menu" HorizontalAlignment="Right" Height="200" VerticalAlignment="Top" Click="MenuButtonOnClick" >
                <StackPanel>
                    <Image Source="Images/smile.png" Height="30"/>
                </StackPanel>
            </k:KinectCircleButton>

        </Grid>
    </k:KinectRegion>
    <WpfViewers:KinectColorViewer HorizontalAlignment="Left" Height="240" Margin="10,10,0,0" VerticalAlignment="Top" Width="320" Kinect="{Binding ElementName=sensorChooserUi, Mode=OneWay, Path=Kinect}"/>


</Grid>

XAML.CS:

public partial class Camera : Page
{
    #region "Kinect"
    private KinectSensorChooser sensorChooser;
    #endregion

    public Camera()
    {

        this.InitializeComponent();
        // initialize the sensor chooser and UI
        this.sensorChooser = new KinectSensorChooser();
        //Assign the sensor chooser with the sensor chooser from the mainwindow. 
        //We are reusing the sensorchoosing declared in the first window that can in contact with kinect
        this.sensorChooser = Generics.GlobalKinectSensorChooser;
        //subscribe to the sensorChooserOnKinectChanged event
        this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
        //Assign Kinect Sensorchooser to the sensorchooser we got from our static class
        this.sensorChooserUi.KinectSensorChooser = sensorChooser;
        // 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);
    }

    private void SensorChooserOnKinectChanged(object sender, KinectChangedEventArgs args)
    {
        bool error = false;
        if (args.OldSensor != null)
        {
            try
            {
                args.OldSensor.DepthStream.Range = DepthRange.Default;
                args.OldSensor.SkeletonStream.EnableTrackingInNearRange = false;
                args.OldSensor.DepthStream.Disable();
                args.OldSensor.SkeletonStream.Disable();

                args.OldSensor.ColorStream.Disable();
            }
            catch (InvalidOperationException)
            {
                // KinectSensor might enter an invalid state while enabling/disabling streams or stream features.
                // E.g.: sensor might be abruptly unplugged.
                error = true;
            }
        }

        if (args.NewSensor != null)
        {
            try
            {
                args.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                args.NewSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                args.NewSensor.SkeletonStream.Enable();
            }
            catch (InvalidOperationException)
            {
                error = true;
                // KinectSensor might enter an invalid state while enabling/disabling streams or stream features.
                // E.g.: sensor might be abruptly unplugged.
            }
        }

        if (!error)
            kinectRegion.KinectSensor = args.NewSensor;
    }

    private void MenuButtonOnClick(object sender, RoutedEventArgs e)
    {
        //Unsubscribe to the sensorchooser's  event SensorChooseronkinectChanged
        this.sensorChooser.KinectChanged -= SensorChooserOnKinectChanged;
        (Application.Current.MainWindow.FindName("_mainFrame") as Frame).Source = new Uri("MainMenu.xaml", UriKind.Relative);
    }
}

チュートリアルでは、私がフォローしていた ( http://channel9.msdn.com/Series/KinectQuickstart/Camera-Fundamentals ) インストラクターは、KinectColorViewer を画面にドロップし、パスを設定するだけで機能します。

4

2 に答える 2

1

KinectColorVieweravailable in the assemblyKinectWpfViewersは「Kinect Explorer」の例で使用されており、それがどのように使用され、どのように動作するかを確認するのに最適な場所です。この例から、XAML でビューアーを初期化する適切な方法と必要なバインディングがわかるでしょう。

投稿したコードから、Kinect 自体 (ハードウェアへの参照) を にバインドしているように見えますがKinectColorViewer、これは期待しているものではありません。アセンブリKinectSensorManagerの一部であるクラスへの参照を設定する必要があります。KinectWpfViewers

これは、単純化された XAML です。KinectColorViewer

<Window x:Class="Microsoft.Samples.Kinect.KinectExplorer.KinectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Microsoft.Samples.Kinect.KinectExplorer"
        xmlns:kt="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers"
        Title="Kinect Explorer" Width="812" Height="768">
    <Grid>
        <kt:KinectColorViewer x:Name="ColorViewer" KinectSensorManager="{Binding KinectSensorManager}" CollectFrameRate="True" RetainImageOnSensorChange="True" />
    </Grid> 
</Window>

次に、XAML.CS コンストラクターは次のようになります。

public KinectWindow()
{
    this.viewModel = new KinectWindowViewModel();

    // The KinectSensorManager class is a wrapper for a KinectSensor that adds
    // state logic and property change/binding/etc support, and is the data model
    // for KinectDiagnosticViewer.
    this.viewModel.KinectSensorManager = new KinectSensorManager();

    Binding sensorBinding = new Binding("KinectSensor");
    sensorBinding.Source = this;
    BindingOperations.SetBinding(this.viewModel.KinectSensorManager, KinectSensorManager.KinectSensorProperty, sensorBinding);

    // Attempt to turn on Skeleton Tracking for each Kinect Sensor
    this.viewModel.KinectSensorManager.SkeletonStreamEnabled = true;

    this.DataContext = this.viewModel;

    InitializeComponent();
}

詳細については、「Kinect Explorer」の例を確認してください。

于 2013-04-16T02:22:50.647 に答える
0

KinectSensorManager の使用でも同じ問題がありました。kinect.dll、kinect.toolkit.dll、kinect.controls.dll だけでなく、Microsoft.Samples.Kinect.Wpf.Viewers を呼び出す必要があることがわかりました。しかし、KinectSensorManager を実装すると、KinectUI と SensorChooser が xaml インターフェイスで動作しなくなりました。

于 2013-04-23T21:14:39.137 に答える