{"id":3348,"date":"2021-06-02T21:02:35","date_gmt":"2021-06-02T13:02:35","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=3348"},"modified":"2021-06-02T21:20:29","modified_gmt":"2021-06-02T13:20:29","slug":"mediapipe-in-touchdesigner-8","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2021\/06\/02\/mediapipe-in-touchdesigner-8\/","title":{"rendered":"MediaPipe in TouchDesigner 8"},"content":{"rendered":"\n<p>The following example presents a more general approach to obtain the hand tracking details in a Script CHOP. We can then use other TouchDesigner CHOPs to extract the data for visualisation. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"577\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-1024x577.png\" alt=\"\" class=\"wp-image-3350\" srcset=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-1024x577.png 1024w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-300x169.png 300w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-768x433.png 768w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-1536x866.png 1536w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-2048x1154.png 2048w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-690x389.png 690w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2021\/06\/HandTrackingCHOP2-980x552.png 980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>For simplicity, it also detects one single hand. For each hand tracked, it will generate 21 landmarks as shown in the diagram from <a href=\"http:\/\/www.magicandlove.com\/blog\/2021\/06\/02\/mediapipe-in-touchdesigner-7\/\">the last post<\/a>. The Script CHOP will produce 2 channels, <strong>hand:x<\/strong> and <strong>hand:y<\/strong>. Each of the channel will have 21 samples, corresponding to the 21 hand landmarks from MediaPipe. The following code segment describes how it is done.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">detail_x = []\ndetail_y = []\nif results.multi_hand_landmarks:\n    for hand in results.multi_hand_landmarks:\n        for pt in hand.landmark:\n            detail_x.append(pt.x)\n            detail_y.append(pt.y)\n\n    tx = scriptOp.appendChan('hand:x')   \n    ty = scriptOp.appendChan('hand:y')  \n    tx.vals = detail_x   \n    ty.vals = detail_y  \n    scriptOp.numSamples = len(detail_x)\n\nscriptOp.rate = me.time.rate\n<\/pre>\n\n\n\n<p>The TouchDesigner project also uses <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.derivative.ca\/Shuffle_CHOP\" target=\"_blank\">Shuffle CHOP<\/a> to swap the 21 samples into 21 channels. We can then select the 5 channels corresponding to the 5 finger tips (4, 8, 12, 16, 20) for visualisation. The final project is available for download in the <a href=\"https:\/\/github.com\/chungbwc\/TouchDesigner\/tree\/main\/MediaPipeHandCHOP2\" target=\"_blank\" rel=\"noreferrer noopener\">MediaPipeHandCHOP2<\/a> folder of the GitHub repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following example presents a more general approach to obtain the hand tracking details in a Script CHOP. We can then use other TouchDesigner CHOPs to extract the data for visualisation. For simplicity, it also detects one single hand. For each hand tracked, it will generate 21 landmarks as shown in the diagram from the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[184,180,182,84],"class_list":["post-3348","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-hand-tracking","tag-mediapipe","tag-python","tag-touchdesigner"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/3348","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=3348"}],"version-history":[{"count":6,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/3348\/revisions"}],"predecessor-version":[{"id":3356,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/3348\/revisions\/3356"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=3348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=3348"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=3348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}