/// <summary> /// Maps the information received for a Body from the Kinect to a /// KinectBody we can serialize and send over the wire. /// </summary> /// <param name="body">Body to map</param> /// <param name="sensorId">Sensor ID, or any other value being used as the device connection Id</param> /// <returns>Mapped KinectBody containing the body information, /// an identifier, and othe processed data</returns> private static KinectBody MapBody(Body body, string sensorId) { var d = new KinectBody(sensorId, body.TrackingId); // All six bodies are fully tracked. Wee! var jointCount = Enum.GetNames(typeof (KinectJointType)).Length; d.Joints = new KinectJoint[jointCount]; for (var i = 0; i < jointCount; i++) { var nativeJoint = body.Joints[(JointType) i]; var orientation = body.JointOrientations[(JointType) i].Orientation; var joint = new KinectJoint { TrackingState = ((KinectTrackingState) (int) nativeJoint.TrackingState), Position = new KinectVector3 { X = nativeJoint.Position.X, Y = nativeJoint.Position.Y, Z = nativeJoint.Position.Z }, JointType = ((KinectJointType) (int) nativeJoint.JointType), Orientation = new KinectVector4 { W = orientation.W, X = orientation.X, Y = orientation.Y, Z = orientation.Z } }; d.Joints[i] = joint; } d.Lean = new KinectPoint {X = body.Lean.X, Y = body.Lean.Y}; d.LeanTrackingState = (KinectTrackingState) (int) body.LeanTrackingState; // Record hand states d.HandLeftState = (KinectHandState) (int) body.HandLeftState; d.HandRightState = (KinectHandState) (int) body.HandRightState; // Record hand confidence. Initially we'll just convert the enum to an int, // but we could do some exponential smoothing between their {0,1} values. d.HandLeftConfidence = (int) body.HandLeftConfidence; d.HandRightConfidence = (int) body.HandRightConfidence; return d; }
protected override bool ProcessBody(KinectBody body) { // If at least three of the arm joints are inferred, as assume there's no arm var inferredCount = body.Joints.Count(x => x.TrackingState == KinectTrackingState.Inferred && (x.JointType == KinectJointType.ElbowLeft || x.JointType == KinectJointType.WristLeft || x.JointType == KinectJointType.HandLeft || x.JointType == KinectJointType.HandTipLeft || x.JointType == KinectJointType.ThumbLeft)); var isMissing = inferredCount >= 4; if (isMissing) { body.Tags.Add("LeftArmMissing"); } return isMissing; }