Hello!
In the last post of the series with basic stuff we can do with KinectSdk V2 and the new KinectOne today I’ll write about how we can “draw a body” or what we use to call a skeleton.
As in the previous examples, we must create a Reader of the type BODYREADER, initialize it and subscribe to the FrameArrived event. In it then
- a couple of null validations
- We get the frame of the Body feed
- We update the array of bodies (remember that with the KinectOne, we can follow up to six bodies simultaneously!)
- for every body access to its collection of Joints and paint them
1: void BodyReaderFrameArrived(object sender, BodyFrameArrivedEventArgs e)
2: {
3: var frameReference = e.FrameReference;
4: try
5: {
6: var frame = frameReference.AcquireFrame();
7: if (frame == null) return;
8: using (frame)
9: {
10: using (var dc = _drawingGroup.Open())
11: {
12: dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, _displayWidth, _displayHeight));
13:
14: frame.GetAndRefreshBodyData(_bodies);
15:
16: foreach (var body in _bodies.Where(body => body.IsTracked))
17: {
18: DrawClippedEdges(body, dc);
19:
20: var joints = body.Joints;
21:
22: // convert the joint points to depth (display) space
23: var jointPoints = new Dictionary<JointType, Point>();
24: foreach (var jointType in joints.Keys)
25: {
26: var depthSpacePoint = _coordinateMapper.MapCameraPointToDepthSpace(joints[jointType].Position);
27: jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
28: }
29:
30: DrawBody(joints, jointPoints, dc);
31: DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
32: DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
33: }
34:
35: // prevent drawing outside of our render area
36: _drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, _displayWidth, _displayHeight));
37: }
38: }
39: }
40: catch { }
41: }
Take a look at the lines 23 to 28, where the SDK already gives us an object to helps us coordinate the spatial position of the joints for the depth of the same information. In KinectSDK previous versions this routine has been improved and with the V2 I think that they have left her in a way my simple and easy to use.
Another point to keep in mind is that now with the ability to detect the State of the hand, now we can change the classic SKELETON to make it a little more fun. I leave a video example
Disclaimer:
“This is preliminary software and/or hardware and APIs are preliminary and subject to change“
Greetings @ Cordoba, land of bbq, friends and guitar
El Bruno
Leave a comment