internal static void CopyToFrameToDrawingContext(this HighDefinitionFaceFrame highDefinitionFaceFrame, DrawingContext context, bool useDepthSpace = true, byte bodyIndex = 1, double pointRadius = 2F) { var faceAlignment = new FaceAlignment(); var coordinateMapper = highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.CoordinateMapper; var brush = BodyIndexColor.GetBrushFromBodyIndex(bodyIndex); highDefinitionFaceFrame.GetAndRefreshFaceAlignmentResult(faceAlignment); var faceModel = new FaceModel(); var vertices = faceModel.CalculateVerticesForAlignment(faceAlignment); if (vertices.Count > 0) { for (int index = 0; index < vertices.Count; index++) { CameraSpacePoint vertice = vertices[index]; DepthSpacePoint point = coordinateMapper.MapCameraPointToDepthSpace(vertice); if (float.IsInfinity(point.X) || float.IsInfinity(point.Y)) { return; } context.DrawEllipse(brush, null, point.GetPoint(), pointRadius, pointRadius); } } }
internal static void CopyToFrameToDrawingContext(this FaceFrame faceFrame, DrawingContext context, bool useInfraredSpace = true, byte bodyIndex = 1, double pointRadius = 1F, double line = 1F) { var brush = BodyIndexColor.GetBrushFromBodyIndex(bodyIndex); var pen = new System.Windows.Media.Pen(brush, line); if (useInfraredSpace) { if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.BoundingBoxInInfraredSpace) == FaceFrameFeatures.BoundingBoxInInfraredSpace) { context.DrawRectangle(null, pen, faceFrame.FaceFrameResult.FaceBoundingBoxInInfraredSpace.ToRect()); } if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.PointsInInfraredSpace) == FaceFrameFeatures.PointsInInfraredSpace) { context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.EyeLeft].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.EyeRight].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.Nose].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerLeft].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerRight].ToPoint(), pointRadius, pointRadius); context.DrawLine(pen, faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerLeft].ToPoint(), faceFrame.FaceFrameResult.FacePointsInInfraredSpace[FacePointType.MouthCornerRight].ToPoint()); } } else { if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.BoundingBoxInColorSpace) == FaceFrameFeatures.BoundingBoxInColorSpace) { context.DrawRectangle(null, pen, faceFrame.FaceFrameResult.FaceBoundingBoxInColorSpace.ToRect()); } if ((faceFrame.FaceFrameResult.FaceFrameFeatures & FaceFrameFeatures.PointsInColorSpace) == FaceFrameFeatures.PointsInColorSpace) { context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.EyeLeft].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.EyeRight].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.Nose].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerLeft].ToPoint(), pointRadius, pointRadius); context.DrawEllipse(brush, null, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerRight].ToPoint(), pointRadius, pointRadius); context.DrawLine(pen, faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerLeft].ToPoint(), faceFrame.FaceFrameResult.FacePointsInColorSpace[FacePointType.MouthCornerRight].ToPoint()); } } }
internal static void CopyToFrameToDrawingContext(this BodyFrame bodyFrame, DrawingContext context, bool drawBones = true, bool useDepthSpace = true, double pointRadius = 3F, double line = 0.8F) { var bodies = new Body[bodyFrame.BodyCount]; var coordinateMapper = bodyFrame.BodyFrameSource.KinectSensor.CoordinateMapper; var trnsparentPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Transparent, 1F); System.Windows.Rect rect; if (useDepthSpace) { rect = bodyFrame.BodyFrameSource.KinectSensor.DepthFrameSource.FrameDescription.GetRect(); } else { rect = bodyFrame.BodyFrameSource.KinectSensor.ColorFrameSource.FrameDescription.GetRect(); } context.DrawRectangle(System.Windows.Media.Brushes.Transparent, null, rect); bodyFrame.GetAndRefreshBodyData(bodies); for (int i = 0; i < bodies.Length; i++) { if (!bodies[i].IsTracked) { continue; } var brush = BodyIndexColor.GetBrushFromBodyIndex(i); foreach (Joint joint in bodies[i].Joints.Values.Where(j => j.TrackingState == TrackingState.Tracked)) { System.Windows.Point point; if (useDepthSpace) { point = coordinateMapper.MapCameraPointToDepthSpace(joint.Position).GetPoint(); } else { point = coordinateMapper.MapCameraPointToColorSpace(joint.Position).GetPoint(); } if (rect.Contains(point)) { context.DrawEllipse(brush, null, point, pointRadius, pointRadius); } } if (drawBones) { DrawBone(context, brush, JointType.Head, JointType.Neck, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.Neck, JointType.SpineShoulder, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineShoulder, JointType.SpineMid, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineMid, JointType.SpineBase, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineShoulder, JointType.ShoulderRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineShoulder, JointType.ShoulderLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineBase, JointType.HipRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.SpineBase, JointType.HipLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.ShoulderRight, JointType.ElbowRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.ElbowRight, JointType.WristRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.WristRight, JointType.HandRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.HandRight, JointType.HandTipRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.WristRight, JointType.ThumbRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.ShoulderLeft, JointType.ElbowLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.ElbowLeft, JointType.WristLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.WristLeft, JointType.HandLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.HandLeft, JointType.HandTipLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.WristLeft, JointType.ThumbLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.HipRight, JointType.KneeRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.KneeRight, JointType.AnkleRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.AnkleRight, JointType.FootRight, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.HipLeft, JointType.KneeLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.KneeLeft, JointType.AnkleLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); DrawBone(context, brush, JointType.AnkleLeft, JointType.FootLeft, bodies[i].Joints, rect, coordinateMapper, useDepthSpace, line); } } }