Difference between revisions of "MediaPipe for TouchDesigner"

From Interaction Station Wiki
Jump to navigation Jump to search
Line 13: Line 13:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 2. Make alias for x86_64 brew ===
+
=== Make alias for x86_64 brew ===
  
 
Add this to rc file (.bashrc, .zshrc etc)
 
Add this to rc file (.bashrc, .zshrc etc)
Line 21: Line 21:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 3. Install python3.7 ===
+
=== Install python3.7 ===
  
 
<syntaxhighlight lang=c style="border:1px dashed black; max-width: 950px;">
 
<syntaxhighlight lang=c style="border:1px dashed black; max-width: 950px;">
Line 27: Line 27:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   
 
   
=== 4. Alias for python@3.7 and pip3 ===
+
=== Alias for python@3.7 and pip3 ===
  
 
Add to rc file
 
Add to rc file
Line 38: Line 38:
 
Now you can use `iPY37` to run x86_64 python@3.7 and `iPIP37` to install packages.
 
Now you can use `iPY37` to run x86_64 python@3.7 and `iPIP37` to install packages.
  
=== 5. Install Mediapipe for python@3.7 x86_64 ===
+
=== Install Mediapipe for python@3.7 x86_64 ===
  
 
<syntaxhighlight lang=c style="border:1px dashed black; max-width: 950px;">
 
<syntaxhighlight lang=c style="border:1px dashed black; max-width: 950px;">
Line 44: Line 44:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 6. Find python@3.7 x86_64 module path ===
+
=== Find python@3.7 x86_64 module path ===
  
 
Find the Python Module path of installed x86_64 python@3.7
 
Find the Python Module path of installed x86_64 python@3.7
Line 56: Line 56:
 
Append `/lib/python3.7/site-packages` to this path to get `/usr/local/lib/python3.7/site-packages`. This is the *Python 64-bit Module Path* you need to fill in TouchDesigner by going to `Preferences -> general -> Python 64-bit Module Path`
 
Append `/lib/python3.7/site-packages` to this path to get `/usr/local/lib/python3.7/site-packages`. This is the *Python 64-bit Module Path* you need to fill in TouchDesigner by going to `Preferences -> general -> Python 64-bit Module Path`
  
=== 7. Restart TouchDesigner ===
+
=== Restart TouchDesigner ===
  
 
Mediapipe should be installed! To verify the installation go to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`
 
Mediapipe should be installed! To verify the installation go to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`
Line 64: Line 64:
 
For windows we need to have a parallel copy of the same Python version on the harddrive. TouchDesigner expects us to work with Python3.7.x so grab this version from the [Python website](https://www.python.org/downloads/windows/). I used [Python 3.7.9](https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe) for this tutorial.
 
For windows we need to have a parallel copy of the same Python version on the harddrive. TouchDesigner expects us to work with Python3.7.x so grab this version from the [Python website](https://www.python.org/downloads/windows/). I used [Python 3.7.9](https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe) for this tutorial.
  
=== 1. Install excecutable ===
+
=== Install excecutable ===
  
 
Double-click the downloaded executable file and install Python to the `DataStorage` drive `E:/` in a folder named `Python`
 
Double-click the downloaded executable file and install Python to the `DataStorage` drive `E:/` in a folder named `Python`
  
=== 2. Installing MediaPipe ===
+
=== Installing MediaPipe ===
  
 
To install MediaPipe for our newly installed Python, open Windows PowerShell and run the following commands
 
To install MediaPipe for our newly installed Python, open Windows PowerShell and run the following commands
Line 90: Line 90:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 3. Open TouchDesigner starter ===
+
=== Open TouchDesigner starter ===
  
 
Download the [MediaPipe starter project](http://interactionstation.wdka.hro.nl/mediawiki/images/a/a5/Mp-starter-toe.zip), unzip it and double-click to open the project in TouchDesigner. If you installed Python3.7 in a different folder than `E:\Python\Lib\site-packages` you need to change the `pythonpath` variable within the `DAT Excecute` OP to the correct folder.
 
Download the [MediaPipe starter project](http://interactionstation.wdka.hro.nl/mediawiki/images/a/a5/Mp-starter-toe.zip), unzip it and double-click to open the project in TouchDesigner. If you installed Python3.7 in a different folder than `E:\Python\Lib\site-packages` you need to change the `pythonpath` variable within the `DAT Excecute` OP to the correct folder.
  
 
To check if you can use MediaPipe in TouchDesigner, navigate to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`.
 
To check if you can use MediaPipe in TouchDesigner, navigate to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`.

Revision as of 17:12, 10 May 2022

MediaPipe for TouchDesigner

On Apple Silicon (M1) using Rosetta2

We will install an emulated x86_64 brew using Rosetta2 alongside native Apple Silicon brew. This way we can install the by TouchDesigner expected python3.7 while also installing the MediaPipe module.

There is a MediaPipe module build for Apple Silicon (M1) machines found at [this Github issue](https://github.com/google/mediapipe/issues/3277), but I couldn't find a native Python 3.7 build for Apple Silicon to run in TouchDesigner.

Install brew x86_64 using Rosetta2

$ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Make alias for x86_64 brew

Add this to rc file (.bashrc, .zshrc etc)

alias ibrew="arch -x86_64 /usr/local/bin/brew"

Install python3.7

$ ibrew install python@3.7

Alias for python@3.7 and pip3

Add to rc file

alias iPY37=/usr/local/opt/python@3.7/bin/python3
alias iPIP37=/usr/local/opt/python@3.7/bin/pip3

Now you can use `iPY37` to run x86_64 python@3.7 and `iPIP37` to install packages.

Install Mediapipe for python@3.7 x86_64

$ iPIP37 install mediapipe

Find python@3.7 x86_64 module path

Find the Python Module path of installed x86_64 python@3.7

$ ibrew --prefix

/usr/local

Append `/lib/python3.7/site-packages` to this path to get `/usr/local/lib/python3.7/site-packages`. This is the *Python 64-bit Module Path* you need to fill in TouchDesigner by going to `Preferences -> general -> Python 64-bit Module Path`

Restart TouchDesigner

Mediapipe should be installed! To verify the installation go to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`

Windows

For windows we need to have a parallel copy of the same Python version on the harddrive. TouchDesigner expects us to work with Python3.7.x so grab this version from the [Python website](https://www.python.org/downloads/windows/). I used [Python 3.7.9](https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe) for this tutorial.

Install excecutable

Double-click the downloaded executable file and install Python to the `DataStorage` drive `E:/` in a folder named `Python`

Installing MediaPipe

To install MediaPipe for our newly installed Python, open Windows PowerShell and run the following commands

$ python

...
Python 3.7.9
...

$ exit()
  • Note: Check if the Python version corresponds with the Python you've installed in step 1.*

Install mediapipe using pip package manager:

$ pip install mediapipe

Open TouchDesigner starter

Download the [MediaPipe starter project](http://interactionstation.wdka.hro.nl/mediawiki/images/a/a5/Mp-starter-toe.zip), unzip it and double-click to open the project in TouchDesigner. If you installed Python3.7 in a different folder than `E:\Python\Lib\site-packages` you need to change the `pythonpath` variable within the `DAT Excecute` OP to the correct folder.

To check if you can use MediaPipe in TouchDesigner, navigate to `Dialogs -> Textport and DATs`, import the MediaPipe module; `import mediapipe as mp` and list the components; `print(dir(mp.solutions))`.