public ClosestBodyFrame(Windows.Kinect.BodyFrame bf, double engageMin, double engageMax) { Type = FrameType.ClosestBody; engageBeginBoundZ = engageMin; engageEndBoundZ = engageMax; Body[] bodies = new Body[bf.BodyCount]; bf.GetAndRefreshBodyData(bodies); double closestDistance = Double.MaxValue; for (int i = 0; i < bodies.Length; i++) { var body = bodies[i]; if (body.IsTracked) { TrackedCount++; } double distance = DistanceFromKinect(body); if (IsEngaged(distance)) { if (body.TrackingId == lastEngagedTrackingId) { closestBody = body; closestIndex = i; break; } else if (distance < closestDistance) { closestBody = body; closestDistance = distance; closestIndex = i; } } } // Enagaged implies BodyFound Debug.Assert(!Engaged || BodyFound); if (!BodyFound) { lastEngagedTrackingId = 0; } else if (TrackingId != lastEngagedTrackingId) { lastEngagedTrackingId = TrackingId; } //Debug.WriteLine("Number of tracked bodies: {0}", trackedCount); }
public Status Update() { Kinect.MultiSourceFrame frame = _Reader.AcquireLatestFrame(); if (frame == null) { //Debug.LogWarning("Frame not arrived"); return(Status.ZeroBody); } Kinect.DepthFrame depthFrame = frame.DepthFrameReference.AcquireFrame(); if (depthFrame == null) { return(Status.ZeroBody); } depthFrame.CopyFrameDataToArray(DepthData); depthFrame.Dispose(); depthFrame = null; Kinect.BodyFrame bodyFrame = frame.BodyFrameReference.AcquireFrame(); if (bodyFrame == null) { return(Status.ZeroBody); } bodyFrame.GetAndRefreshBodyData(_BodyData); bodyFrame.Dispose(); bodyFrame = null; int bodyIdx; Status status; checkTrackedBody(out bodyIdx, out status); if (status != Status.ZeroBody) { JointData = _BodyData[bodyIdx].Joints; JointOriendationData = _BodyData[bodyIdx].JointOrientations; } return(status); }
// Update is called once per frame void Update() { // process bodies bool newBodyData = false; using (Kinect.BodyFrame bodyFrame = this.bodyFrameReader.AcquireLatestFrame()) { if (bodyFrame != null) { bodyFrame.GetAndRefreshBodyData(this.bodies); newBodyData = true; } } if (newBodyData) { List <ulong> trackedIds = new List <ulong>(); foreach (var body in bodies) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } List <ulong> knownIds = new List <ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } // update gesture detectors with the correct tracking id for (int bodyIndex = 0; bodyIndex < this.bodyCount; bodyIndex++) { var body = this.bodies [bodyIndex]; if (body != null) { var trackingId = body.TrackingId; if (body.IsTracked == true) { thisbody = bodyIndex; handasmouse(body); if (!_Bodies.ContainsKey(body.TrackingId)) { Debug.Log("Create"); _Bodies [body.TrackingId] = CreateBodyObject(body.TrackingId); } Debug.Log("RE"); RefreshBodyObject(body, _Bodies [body.TrackingId]); // real_time_real_time_skeleton_detect (body); } // if the current body TrackingId changed, update the corresponding gesture detector with the new value /* * if (trackingId != this.gestureDetectorList [bodyIndex].TrackingId) { * //GestureTextGameObject.text = "none"; * * //this.bodyText[bodyIndex] = "none"; * this.gestureDetectorList [bodyIndex].TrackingId = trackingId; * * // if the current body is tracked, unpause its detector to get VisualGestureBuilderFrameArrived events * // if the current body is not tracked, pause its detector so we don't waste resources trying to get invalid gesture results * this.gestureDetectorList [bodyIndex].IsPaused = (trackingId == 0); * this.gestureDetectorList [bodyIndex].OnGestureDetected += CreateOnGestureHandler (bodyIndex); * }*/ } } } }
void Update() { if (_Reader != null) { _Frame = _Reader.AcquireLatestFrame(); if (_Frame != null) { //_vec4 = _Frame.FloorClipPlane; //Vector3 normalVector = new Vector3 (_vec4.X, _vec4.Y, _vec4.Z); if (_Data == null) { _Data = new Body[_Sensor.BodyFrameSource.BodyCount]; } _Frame.GetAndRefreshBodyData(_Data); NewFrame(this, _Frame); _Frame.Dispose(); _Frame = null; } } }