当前位置: 首页>>代码示例>>C#>>正文


C# Body.Any方法代码示例

本文整理汇总了C#中Body.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Body.Any方法的具体用法?C# Body.Any怎么用?C# Body.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Body的用法示例。


在下文中一共展示了Body.Any方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TrackBodies

        /// <summary>
        /// Manages Body Tracking Id by detecting when a body moves is front of an existing body and the existing body loses it's body
        /// </summary>
        /// <param name="bodies">The Kinect bodies collection</param>
        public void TrackBodies(Body[] bodies)
        {
            bool writeOutput = false;

            //if our body count hasn't changed just return null
            //we're doing this for performance
            //this could fail if someone quickly runs in front of a existing body or if an existing player leaves quickly and a new player enters quickly at the same time
            if (bodies.Where(b => b.IsTracked).Count() == TrackedKinectBodyCount)
            {
                CleanupMissingBodies();
                CleanupHijackedBodies();
                return;
            }

            #region debug output
            #if DEBUG
            {
                if (writeOutput)
                {
                    System.Diagnostics.Debug.Print("-------------------- Tracking Bodies ---------------------- ");

                    var trackedBodies = bodies.Where(b => b.IsTracked);
                    System.Diagnostics.Debug.Print("trackedBodies Count:{0}", trackedBodies.Count());
                    var ghostBodies = bodies.Where(b => b.Joints.Count(joint => joint.Key == JointType.Head && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.Neck && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.ShoulderLeft && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.ShoulderRight && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.ElbowLeft && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.ElbowRight && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.WristLeft && joint.Value.TrackingState == TrackingState.Tracked
                                                                    || joint.Key == JointType.WristRight && joint.Value.TrackingState == TrackingState.Tracked) >= RequiredJointsTrackedCount);
                    System.Diagnostics.Debug.Print("ghostBodies Count:{0}", ghostBodies.Count());
                }

                if (writeOutput && _trackedBodiesMissing != null && _trackedBodiesMissing.Count() > 0)
                {
                    foreach (var missingBody in _trackedBodiesMissing)
                    {
                        System.Diagnostics.Debug.Print("MissingBody Output - CorrelatedPlayerId:{0}, CurrentPlayerTrackingId:{1}, BodyPosition.X:{2}, BodyPosition.Y:{3}, BodyPosition.Z{4}, TimeWentMissing{5}",
                            missingBody.CorrelationPlayerId
                            , missingBody.CurrentPlayerTrackingId
                            , missingBody.BodyPosition.X
                            , missingBody.BodyPosition.Y
                            , missingBody.BodyPosition.Z
                            , missingBody.TimeWentMissing.ToString());

                        foreach (var trackingId in missingBody.PlayerTrackingIds)
                            System.Diagnostics.Debug.Print("MissingBody Output PlayerTrackingIds for CorrelatedPlayerID: {0} - {1}", missingBody.CorrelationPlayerId, trackingId);
                    }

                }
                else if (writeOutput)
                    System.Diagnostics.Debug.Print("MissingBody Output - there are no missing bodies ");

                if (writeOutput && bodies.Any(b => b.IsTracked) && _trackedBodies != null)
                {
                    foreach (var body in bodies.Where(b => b.IsTracked))
                        System.Diagnostics.Debug.Print("Body - IsTracked:{0}, TrackingId:{1}, X:{2}, Y:{3}, Z{4}", body.IsTracked, body.TrackingId, body.Joints[BodyPositionJoint].Position.X, body.Joints[BodyPositionJoint].Position.Y, body.Joints[BodyPositionJoint].Position.Z);

                    foreach (var tb in _trackedBodies)
                    {
                        System.Diagnostics.Debug.Print("TrackedBody - BodyIsTracked:{0}, BodyTrackingId:{1}, TrackedBodyCorrelatedPlayerId:{2}, TrackedBodyCurrentPlayerTrackingId:{3}, BodyX:{4}, BodyY:{5}, BodyZ{6}, TrackedBodyX:{7}, TrackedBodyY:{8}, TrackedBodyZ{9}"
                            , tb.Value.IsTracked
                            , tb.Value.TrackingId
                            , tb.Key.CorrelationPlayerId
                            , tb.Key.CurrentPlayerTrackingId
                            , tb.Value.Joints[BodyPositionJoint].Position.X
                            , tb.Value.Joints[BodyPositionJoint].Position.Y
                            , tb.Value.Joints[BodyPositionJoint].Position.Z
                            , tb.Key.BodyPosition.X
                            , tb.Key.BodyPosition.Y
                            , tb.Key.BodyPosition.Z);

                        foreach (var trackingId in tb.Key.PlayerTrackingIds)
                            System.Diagnostics.Debug.Print("PlayerTrackingIds for CorrelatedPlayerID: {0} - {1}", tb.Key.CorrelationPlayerId, trackingId);
                    }
                }
            }
            #endif //DEBUG
            #endregion debug output

            if (bodies != null && bodies.Length > 0)
            {
                //first time in, just add bodies to TrackedBodies collection
                if (_trackedBodies.Count() == 0)
                {
                    foreach (var body in bodies)
                    {
                        var trackedBody = new TrackedBody(this)
                        {
                            BodyPosition = body.Joints[BodyPositionJoint].Position,
                        };
                        trackedBody.PlayerTrackingIds.Add(body.TrackingId);
                        _trackedBodies.Add(trackedBody, body);
                    }
                }
//.........这里部分代码省略.........
开发者ID:jesjesd,项目名称:KAIT,代码行数:101,代码来源:BodyTrackingService.cs

示例2: ManageMissingBodies

        public void ManageMissingBodies(Body[] bodies)
        {
            bool writeOutput = false;

            #region handle missing Bodies
            //A Missing Body Candidate is initially identified by a TrackedBody that has a .Key.CurrentPlayerTrackingId that does not match the body.Tracking Id
            //we could also use IsTracked flag (body.IsTracked and Key.CurrentPlayerTrackingId != 0)
            //once we have a candidate missing body we need to check if it is missing because it disappaearred while in the viewing area or if it just gradually- walked out of the viewing area

            var missingTrackedBodies = (from trackedBodies in _trackedBodies
                                        where !bodies.Any(b => b.TrackingId == trackedBodies.Key.CurrentPlayerTrackingId)
                                        && !_trackedBodiesMissing.Any(tbMissing => tbMissing.CurrentPlayerTrackingId == trackedBodies.Key.CurrentPlayerTrackingId)
                                        && !_trackedBodiesHijacked.Any(tbHijacked => tbHijacked.CurrentPlayerTrackingId == trackedBodies.Key.CurrentPlayerTrackingId)
                                        select trackedBodies);

            foreach (var missingTrackedBody in missingTrackedBodies)
            {
                //check if the body was within the viewing area before being lost, if it was assume it's missing due to someone walking in front of it
                if (missingTrackedBody.Key.BodyPosition.X > MissingBodyLeftEdgeBoundary && missingTrackedBody.Key.BodyPosition.X < MissingBodyRightEdgeBoundary
                    && missingTrackedBody.Key.BodyPosition.Z < MissingBodyBackDepthBoundary)
                {
                    #region debug output
            #if DEBUG
                    {
                        if (writeOutput)
                        {
                            System.Diagnostics.Debug.Print("MISSING FromTrackedBody - CorrelatedPlayerId:{0}, CurrentPlayerTrackingId{1}, TrackedBodyX:{2}, TrackedBodyY:{3}, TrackedBodyZ{4}"
                            , missingTrackedBody.Key.CorrelationPlayerId
                            , missingTrackedBody.Key.CurrentPlayerTrackingId
                            , missingTrackedBody.Key.BodyPosition.X
                            , missingTrackedBody.Key.BodyPosition.Y
                            , missingTrackedBody.Key.BodyPosition.Z);

                            foreach (var trackingId in missingTrackedBody.Key.PlayerTrackingIds)
                                System.Diagnostics.Debug.Print("MISSING FromTrackedBody - PlayerTrackingIds for CorrelatedPlayerId: {0} - {1}", missingTrackedBody.Key.CorrelationPlayerId, trackingId);
                        }
                    }
            #endif
                    #endregion debug output

                    //create missing body and add to missing body collection
                    var newMissingBody = new TrackedBody(this)
                    {
                        BodyPosition = new CameraSpacePoint() { X = missingTrackedBody.Key.BodyPosition.X, Y = missingTrackedBody.Key.BodyPosition.Y, Z = missingTrackedBody.Key.BodyPosition.Z },
                    };

                    foreach (var trackedPlayerId in missingTrackedBody.Key.PlayerTrackingIds)
                    {
                        newMissingBody.PlayerTrackingIds.Add(trackedPlayerId);
                    }
                    newMissingBody.TimeWentMissing = DateTime.Now;
                    _trackedBodiesMissing.Add(newMissingBody);

                    #region debug output
            #if DEBUG
                    {
                        if (writeOutput)
                        {
                            System.Diagnostics.Debug.Print("MissingBody Added - CorrelatedPlayerID:{0}, CurrentPlayerId{1}, BodyPosition.X{2}, BodyPosition.Y{3}, BodyPosition.Z{4}, TimeWentMissing{5}"
                                , newMissingBody.CorrelationPlayerId
                                , newMissingBody.CurrentPlayerTrackingId
                                , newMissingBody.BodyPosition.X
                                , newMissingBody.BodyPosition.Y
                                , newMissingBody.BodyPosition.Z
                                , newMissingBody.TimeWentMissing.ToString());
                            foreach (var trackingId in newMissingBody.PlayerTrackingIds)
                                System.Diagnostics.Debug.Print("MissingBody Added - PlayerTrackingIds for CorrelatedPlayerId: {0} - {1}", newMissingBody.CorrelationPlayerId, trackingId);
                        }
                    }
            #endif
                    #endregion end debug output
                }

                //sync up the TrackedBody associated with the missing body with it's new body
                missingTrackedBody.Key.PlayerTrackingIds.Clear();
                missingTrackedBody.Key.PlayerTrackingIds.Add(missingTrackedBody.Value.TrackingId);
                missingTrackedBody.Key.BodyPosition = missingTrackedBody.Value.Joints[BodyPositionJoint].Position;
            }
            #endregion handle missing bodies

            #region clean up Missing Bodies

            #region debug output
            //#if DEBUG
            //                    {
            //                        if (writeOutput)
            //                        {
            //                            System.Diagnostics.Debug.Print("TrackedMissingBody Count before Removing expired missing bodies {0}", TrackedBodiesMissing.Count());
            //                            System.Diagnostics.Debug.Print("TrackedMissingBodies Count to be removed:{0}", TrackedBodiesMissing.Where(tb => tb.TimeWentMissing.Value.AddSeconds(+_missingBodyExpiredTimeLimit) < DateTime.Now).Count());

            //                            foreach (var trackedMissingBody in TrackedBodiesMissing.Where(tb => tb.TimeWentMissing.Value.AddSeconds(+_missingBodyExpiredTimeLimit) < DateTime.Now))
            //                                System.Diagnostics.Debug.Print("MissingBody to be Removed - Missing Body CorrelatedPlayerId:{0}, CurrentPlayerId:{1}", trackedMissingBody.CorrelationPlayerId, trackedMissingBody.CurrentPlayerTrackingId);
            //                        }
            //                    }
            //#endif
            #endregion debug output

            CleanupMissingBodies();

            #region debug output
//.........这里部分代码省略.........
开发者ID:jesjesd,项目名称:KAIT,代码行数:101,代码来源:BodyTrackingService.cs


注:本文中的Body.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。