繁体   English   中英

当Kinect跟踪骨骼时如何播放视频

[英]How to play a video when a kinect track a skeleton

因此,我想创建一个事件,当Kinect跟踪骨骼时将播放视频。 我正在使用Visual Studio 2013,Windows的Kinect和kinect模板(VS2012)。 但是,尽管该模板适用于2012年,但仍可在2013年使用。

这是Kinect Contrib模板的链接: 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检测到骨骼时如何播放视频? 谢谢。

runtime_SkeletonFrameReady将每1/30秒触发一次。 因此,每1/30秒您将重置源并按下播放。 因此,视频每隔1/30秒才重新开始播放,这就是为什么您可能看不到视频播放的原因。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM