如何在kinect跟踪骨架时播放视频

时间:2014-04-29 06:53:01

标签: c# wpf video visual-studio-2013 kinect

所以,我想创建一个在kinect跟踪骨架时播放视频的事件。我使用的是visual studio 2013,Kinect for Windows和kinect contrib模板(VS2012)。但是,尽管该模板适用于2012年,但它仍然在2013年开始运作。

这是Kinect Contrib Template的链接:http://kinectcontrib.codeplex.com/releases/view/97477

这是我尝试过的代码:

这是我的XAML:

<Window x:Class="KinectSkeletonApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    WindowState="Maximized" WindowStyle="None">
<Grid>
    <Image Name="videoImage"></Image>
    <Canvas Background="Transparent">
        <MediaElement x:Name="VideoControl" Height="527" Width="760" Visibility="Collapsed"
                      LoadedBehavior="Manual" UnloadedBehavior="Stop" />
    </Canvas>
</Grid>

这是我的xaml.cs:

void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        bool receivedData = false;

        using (SkeletonFrame SFrame = e.OpenSkeletonFrame())
        {
            if (SFrame == null)
            {
                // The image processing took too long. More than 2 frames behind.
            }
            else
            {
                skeletonData = new Skeleton[SFrame.SkeletonArrayLength];
                SFrame.CopySkeletonDataTo(skeletonData);
                receivedData = true;
            }
        }

        if (receivedData)
        {
            Skeleton currentSkeleton = (from s in skeletonData
                                        where s.TrackingState == SkeletonTrackingState.Tracked
                                        select s).FirstOrDefault();

            if (currentSkeleton != null) //When Kinect detect a skeleton
            {
                //Test Event Video
                VideoControl.Visibility = Visibility.Visible;
                VideoControl.Source = new Uri("Videos/1.wmv");
                VideoControl.Play();
            }
            else //When there is no skeleton detected
            {
                //Test Event Video
                VideoControl.Visibility = Visibility.Collapsed;
                VideoControl.Stop();
            }
        }
    }

但接下来发生的事情是视频不会播放。那么,当Kinect检测到骨架时如何播放视频?感谢。

1 个答案:

答案 0 :(得分:2)

每隔1/30秒就会触发runtime_SkeletonFrameReady。所以每1/30秒你都要重置源并按下播放。因此,视频每1/30秒重新启动一次,这就是您可能没有看到视频播放的原因。

您需要检查视频控件是否已播放并调整播放/停止代码。

相关问题