Exemple #1
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);
                }
            }
        }
Exemple #2
0
        public override void Update()
        {
            if (bodyReader != null)
            {
                getMainUser();
            }

            foreach (var viewer in viewers)
            {
                viewer.Update(bodyData, 0);
            }

            // Get the pose.
            if (currentBody != null && currentBody.IsTracked)
            {
                // Encapsulate the important frame data
                SkeletonFrameData frameData = new SkeletonFrameData();
                frameData.TrackingId = currentBody.TrackingId;
                frameData.IsTracked  = currentBody.IsTracked;

                // Build the skeleton
                for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
                {
                    NUIJointType jointType = NUICaptureHelper.JointTypeToNUIJointTypeMapping(jt);

                    Vector3 position = new Vector3(currentBody.Joints[jt].Position.X, currentBody.Joints[jt].Position.Y, currentBody.Joints[jt].Position.Z);
                    position.z *= -1; // Should probably be done with meta data/mapper to avoid disturbing raw data.

                    Quaternion orientation = new Quaternion(currentBody.JointOrientations[jt].Orientation.X, currentBody.JointOrientations[jt].Orientation.Y, currentBody.JointOrientations[jt].Orientation.Z, currentBody.JointOrientations[jt].Orientation.W);

                    frameData.AddJoint(jointType, position, orientation, (CinemaSuite.CinemaMocap.System.Core.TrackingState)currentBody.Joints[jt].TrackingState);
                }

                // Hand info
                frameData.LeftHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandLeftConfidence;
                frameData.LeftHandState      = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandLeftState;

                frameData.RightHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandRightConfidence;
                frameData.RightHandState      = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandRightState;

                // Frame info
                frameData.ClippedEdges = (CinemaSuite.CinemaMocap.System.Core.FrameEdges)currentBody.ClippedEdges;

                FrameDataEventArgs args = new FrameDataEventArgs(frameData);
                OnFrameCaptured(args);
            }
        }
        public override void Update()
        {
            if (ZigEditorInput.Instance.ReaderInited)
            {
                // Update Device
                ZigEditorInput.Instance.Update();

                // Get the tracked user
                ZigTrackedUser user   = null;
                int            userId = 0;
                foreach (KeyValuePair <int, ZigTrackedUser> trackedUser in ZigEditorInput.Instance.TrackedUsers)
                {
                    user   = trackedUser.Value;
                    userId = trackedUser.Key;
                }

                // Update viewers
                foreach (Kinect1EditorViewer viewer in viewers)
                {
                    viewer.Update(ZigEditorInput.Instance, userId);
                }

                if (user != null && user.SkeletonTracked)
                {
                    // Encapsulate the important frame data
                    SkeletonFrameData frameData = new SkeletonFrameData();
                    frameData.TrackingId = (ulong)user.Id;
                    frameData.IsTracked  = user.SkeletonTracked;

                    foreach (ZigInputJoint inputJoint in user.Skeleton)
                    {
                        NUIJointType jointType = NUICaptureHelper.ZigToNUIJointMapping(inputJoint.Id);

                        // Convert position from mm to meters
                        Vector3    position    = inputJoint.Position / 1000f;
                        Quaternion orientation = inputJoint.Rotation;

                        frameData.AddJoint(jointType, position, orientation, inputJoint.Inferred ? TrackingState.Inferred : TrackingState.Tracked);
                    }

                    FrameDataEventArgs args = new FrameDataEventArgs(frameData);
                    OnFrameCaptured(args);
                }
            }
        }