{"id":1068,"date":"2012-08-25T11:13:15","date_gmt":"2012-08-25T03:13:15","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1068"},"modified":"2012-08-25T16:09:54","modified_gmt":"2012-08-25T08:09:54","slug":"kinect-for-windows-for-processing-3","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2012\/08\/25\/kinect-for-windows-for-processing-3\/","title":{"rendered":"Kinect for Windows in Processing 3"},"content":{"rendered":"<p>Finally, the skeleton part of the library is done. In this very experimental version, I extract only one skeleton and store the joints information in an array (size 20) of <a href=\"http:\/\/processing.org\/reference\/PVector.html\">PVector<\/a> type in Processing. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/nuisensor.nui_skeleton_position_tracking_state\">tracking state<\/a> is not implemented yet. I use the z-depth value to indicate if that joint is validly tracked or not. The x and y values are normalized to the range from 0 to 1 in the screen space. In the next version, I would like to implement the async event of tracking. It is time to integrate the all three components:<\/p>\n<ol>\n<li>Individual RGB and depth images<\/li>\n<li>Aligned RGB and depth image<\/li>\n<li>Skeleton tracking<\/li>\n<\/ol>\n<p>&nbsp;<br \/>\n<iframe loading=\"lazy\" width=\"480\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/8Yq6mM9NxIM?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>\n&nbsp;<br \/>\nHere is a copy of the sample Processing code.<\/p>\n<pre lang=\"java\">import pKinect.PKinect;\r\n\r\nPKinect kinect;\r\nPVector [] loc;\r\n\r\nvoid setup()\r\n{\r\n  size(640, 480);\r\n  kinect = new PKinect(this);\r\n  smooth();\r\n  noFill();\r\n  stroke(255, 255, 0);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  background(0);\r\n  loc = kinect.getSkeleton();\r\n  drawSkeleton();\r\n}\r\n\r\nvoid drawSkeleton()\r\n{\r\n  \/\/ Body\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_HEAD,\r\n  kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER,\r\n  kinect.NUI_SKELETON_POSITION_SHOULDER_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER,\r\n  kinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SHOULDER_CENTER,\r\n  kinect.NUI_SKELETON_POSITION_SPINE);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SPINE,\r\n  kinect.NUI_SKELETON_POSITION_HIP_CENTER);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_HIP_CENTER,\r\n  kinect.NUI_SKELETON_POSITION_HIP_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_HIP_CENTER,\r\n  kinect.NUI_SKELETON_POSITION_HIP_RIGHT);\r\n\r\n  \/\/ Left Arm\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SHOULDER_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_ELBOW_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_ELBOW_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_WRIST_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_WRIST_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_HAND_LEFT);\r\n\r\n  \/\/ Right Arm\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_ELBOW_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_WRIST_RIGHT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_WRIST_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_HAND_RIGHT);\r\n\r\n  \/\/ Left Leg\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_HIP_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_KNEE_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_KNEE_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_ANKLE_LEFT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_ANKLE_LEFT,\r\n  kinect.NUI_SKELETON_POSITION_FOOT_LEFT);\r\n\r\n  \/\/ Right Leg\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_HIP_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_KNEE_RIGHT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_KNEE_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_ANKLE_RIGHT);\r\n  DrawBone(kinect.NUI_SKELETON_POSITION_ANKLE_RIGHT,\r\n  kinect.NUI_SKELETON_POSITION_FOOT_RIGHT);\r\n}\r\n\r\nvoid DrawBone(int _s, int _e)\r\n{\r\n  if (loc == null)\r\n  {\r\n    return;\r\n  }\r\n  PVector p1 = loc[_s];\r\n  PVector p2 = loc[_e];\r\n  if (p1.z == 0.0 || p2.z == 0.0)\r\n  {\r\n    return;\r\n  }\r\n  line(p1.x*width, p1.y*height, p2.x*width, p2.y*height);\r\n}<\/pre>\n<p>This version of the code (for Windows 7, both 32-bit and 64-bit) is available <a href=\"http:\/\/www.magicandlove.com\/software\/PKinect_Skel002.zip\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finally, the skeleton part of the library is done. In this very experimental version, I extract only one skeleton and store the joints information in an array (size 20) of PVector type in Processing. The tracking state is not implemented yet. I use the z-depth value to indicate if that joint is validly tracked or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,66],"tags":[40,62],"class_list":["post-1068","post","type-post","status-publish","format-standard","hentry","category-software-2","category-testing","tag-kinect","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1068"}],"version-history":[{"count":9,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1068\/revisions"}],"predecessor-version":[{"id":1070,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1068\/revisions\/1070"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1068"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}