{"id":1089,"date":"2012-08-31T12:28:22","date_gmt":"2012-08-31T04:28:22","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1089"},"modified":"2012-09-04T22:21:29","modified_gmt":"2012-09-04T14:21:29","slug":"kinect-in-windows-for-processing-5","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2012\/08\/31\/kinect-in-windows-for-processing-5\/","title":{"rendered":"Kinect in Windows for Processing 5"},"content":{"rendered":"<p>This is a more or less finished version of the Kinect for Processing library. It includes the basic skeleton tracking, the RGB image, depth image and a mask image. I shall move the related posts to the research page with more documentation on the data structure and method description. Stay tune.<br \/>\n&nbsp;<br \/>\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/xvrvX6LVUgQ?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>\n&nbsp;<br \/>\nThe sample Processing code:<\/p>\n<pre lang=\"java\">\r\nimport pKinect.PKinect;\r\nimport pKinect.SkeletonData;\r\n\r\nPKinect kinect;\r\nPFont font;\r\nArrayList<SkeletonData> bodies;\r\nPImage img;\r\n\r\nvoid setup()\r\n{\r\n  size(640, 480);\r\n  background(0);\r\n  kinect = new PKinect(this);\r\n  bodies = new ArrayList<SkeletonData>();\r\n  smooth();\r\n  font = loadFont(\"LucidaSans-18.vlw\");\r\n  textFont(font, 18);\r\n  textAlign(CENTER);\r\n  img = loadImage(\"background.png\");\r\n}\r\n\r\nvoid draw()\r\n{\r\n  background(0);\r\n  image(kinect.GetImage(), 320, 0, 320, 240);\r\n  image(kinect.GetDepth(), 320, 240, 320, 240);\r\n  image(img, 0, 240, 320, 240);\r\n  image(kinect.GetMask(), 0, 240, 320, 240);\r\n  for (int i=0; i<bodies.size(); i++) \r\n  {\r\n    drawSkeleton(bodies.get(i));\r\n    drawPosition(bodies.get(i));\r\n  }\r\n}\r\n\r\nvoid mousePressed() \r\n{\r\n  println(frameRate);\r\n}\r\n\r\nvoid drawPosition(SkeletonData _s) \r\n{\r\n  noStroke();\r\n  fill(0, 100, 255);\r\n  String s1 = str(_s.dwTrackingID);\r\n  text(s1, _s.position.x*width\/2, _s.position.y*height\/2);\r\n}\r\n\r\nvoid drawSkeleton(SkeletonData _s) \r\n{\r\n  \/\/ Body\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HEAD, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_CENTER);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_CENTER, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_CENTER, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_CENTER, \r\n  PKinect.NUI_SKELETON_POSITION_SPINE);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_SPINE);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_SPINE);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SPINE, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_CENTER);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_CENTER, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_CENTER, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_RIGHT);\r\n\r\n  \/\/ Left Arm\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_ELBOW_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_ELBOW_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_WRIST_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_WRIST_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_HAND_LEFT);\r\n\r\n  \/\/ Right Arm\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_SHOULDER_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_ELBOW_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_ELBOW_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_WRIST_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_WRIST_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_HAND_RIGHT);\r\n\r\n  \/\/ Left Leg\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_KNEE_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_KNEE_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_ANKLE_LEFT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_ANKLE_LEFT, \r\n  PKinect.NUI_SKELETON_POSITION_FOOT_LEFT);\r\n\r\n  \/\/ Right Leg\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_HIP_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_KNEE_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_KNEE_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_ANKLE_RIGHT);\r\n  DrawBone(_s, \r\n  PKinect.NUI_SKELETON_POSITION_ANKLE_RIGHT, \r\n  PKinect.NUI_SKELETON_POSITION_FOOT_RIGHT);\r\n}\r\n\r\nvoid DrawBone(SkeletonData _s, int _j1, int _j2) \r\n{\r\n  noFill();\r\n  stroke(255, 255, 0);\r\n  if (_s.skeletonPositionTrackingState[_j1] != PKinect.NUI_SKELETON_POSITION_NOT_TRACKED &#038;&#038;\r\n    _s.skeletonPositionTrackingState[_j2] != PKinect.NUI_SKELETON_POSITION_NOT_TRACKED) {\r\n    line(_s.skeletonPositions[_j1].x*width\/2, \r\n    _s.skeletonPositions[_j1].y*height\/2, \r\n    _s.skeletonPositions[_j2].x*width\/2, \r\n    _s.skeletonPositions[_j2].y*height\/2);\r\n  }\r\n}\r\n\r\nvoid appearEvent(SkeletonData _s) \r\n{\r\n  if (_s.trackingState == PKinect.NUI_SKELETON_NOT_TRACKED) \r\n  {\r\n    return;\r\n  }\r\n  synchronized(bodies) {\r\n    bodies.add(_s);\r\n  }\r\n}\r\n\r\nvoid disappearEvent(SkeletonData _s) \r\n{\r\n  synchronized(bodies) {\r\n    for (int i=bodies.size()-1; i>=0; i--) \r\n    {\r\n      if (_s.dwTrackingID == bodies.get(i).dwTrackingID) \r\n      {\r\n        bodies.remove(i);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nvoid moveEvent(SkeletonData _b, SkeletonData _a) \r\n{\r\n  if (_a.trackingState == PKinect.NUI_SKELETON_NOT_TRACKED) \r\n  {\r\n    return;\r\n  }\r\n  synchronized(bodies) {\r\n    for (int i=bodies.size()-1; i>=0; i--) \r\n    {\r\n      if (_b.dwTrackingID == bodies.get(i).dwTrackingID) \r\n      {\r\n        bodies.get(i).copy(_a);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>You can download the example and the library <a href=\"http:\/\/www.magicandlove.com\/software\/PKinect_Skel006.zip\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a more or less finished version of the Kinect for Processing library. It includes the basic skeleton tracking, the RGB image, depth image and a mask image. I shall move the related posts to the research page with more documentation on the data structure and method description. Stay tune. &nbsp; &nbsp; The sample [&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],"tags":[23,40,62],"class_list":["post-1089","post","type-post","status-publish","format-standard","hentry","category-software-2","tag-interaction-design","tag-kinect","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1089","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=1089"}],"version-history":[{"count":2,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1089\/revisions"}],"predecessor-version":[{"id":1091,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1089\/revisions\/1091"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1089"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}