Exemplo n.º 1
0
        private void InputProfile_FrameSelected(object sender, FrameSelectedEventArgs args)
        {
            previousArgs = args;
            if (MappingProfile != null && OutputProfile != null)
            {
                cache = new CaptureCache();

                // Build the cache
                int startingFrame = BaseSystem.Math.Max(args.frame - cache.CacheSize, 0);

                for (int i = startingFrame; i <= args.frame; i++)
                {
                    var elapsedTime = args.session.CaptureData[i].ElapsedMilliseconds;
                    var skeleton    = NUICaptureHelper.GetNUISkeleton(args.session.CaptureData[i].Skeleton);

                    cache.AddNewFrame(skeleton, elapsedTime);

                    // Filter the raw input with enabled filters.
                    NUISkeleton filtered = skeleton;
                    foreach (MocapFilter filter in preMapFilters)
                    {
                        if (filter.Enabled)
                        {
                            filtered = filter.Filter(cache);
                            cache.AddFiltered(filter.Name, filtered);
                        }
                    }

                    // Convert the input skeleton to the normalized skeleton (Unity)
                    NUISkeleton mapped = MappingProfile.MapSkeleton(filtered);
                    cache.AddMapped(mapped);

                    // Apply any post-mapped filters selected by the user.
                    filtered = mapped;
                    foreach (MocapFilter filter in postMapFilters)
                    {
                        if (filter.Enabled)
                        {
                            filtered = filter.Filter(cache);
                            cache.AddFiltered(filter.Name, filtered);
                        }
                    }
                    cache.AddResult(filtered);
                }

                var s = NUICaptureHelper.GetNUISkeleton(args.session.CaptureData[args.frame].Skeleton);
                OutputProfile.UpdatePreview(cache.CurrentSkeleton, MappingProfile.GetHipPosition(s));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receive frame data from the Input profile.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void MocapProfile_SkeletonFrameCaptured(object sender, FrameDataEventArgs args)
        {
            if (MappingProfile != null && OutputProfile != null)
            {
                var elapsedTime = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks);
                var skeleton    = NUICaptureHelper.GetNUISkeleton(args.SkeletonFrameData);

                // Cache raw data
                cache.AddNewFrame(skeleton, elapsedTime.TotalMilliseconds);

                // Filter the raw input with enabled filters.
                NUISkeleton filtered = skeleton;
                foreach (MocapFilter filter in preMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }

                // Convert the input skeleton to the normalized skeleton (Unity)
                NUISkeleton mapped   = MappingProfile.MapSkeleton(skeleton);
                Vector3     position = MappingProfile.GetHipPosition(skeleton);
                cache.AddMapped(mapped);

                // Apply any post-mapped filters selected by the user.
                filtered = mapped;
                foreach (MocapFilter filter in postMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }

                // Send the mapped and filtered skeleton to the output profile.
                cache.AddResult(filtered);
                OutputProfile.UpdatePreview(filtered, position);

                if (session != null && captureState == RecordingState.Recording)
                {
                    // Add frame to session.
                    MocapSessionKeyframe kf = new MocapSessionKeyframe(args.SkeletonFrameData, (int)elapsedTime.TotalMilliseconds);
                    session.CaptureData.Add(kf);
                }
            }
        }