I made this as a way to get face tracking to happen easily in TouchDesigner since it didn't seem like there was a simple way to make it happen. This method uses the clmtrackr JavaScript library to do the face tracking in your web browser, using your webcam. It then sends that data as JSON via a WebSocket to a waiting server in TouchDesigner.
Read below or watch this short YouTube video for the details: https://www.youtube.com/watch?v=HtmxhGLojcQ
- Create a network with a Web Server DAT
- Set that operator's "Port" parameter to a port number (like
12000) and turn the "Active" parameter on - Edit the
onWebSocketReceiveTextfunction in the attached callbacks window to contain the lineop('text1').text = data - Create a Text DAT (named
text1) and change its "Content Language" parameter toJSON - Connect the output of the Text DAT to a JSON DAT and change its "Output Format" parameter to
Table - Connect the output of the JSON DAT to a DAT to CHOP
- Download the
index.htmlfile and put it in a folder on your computer - Open the file in your browser (probably using Ctrl+O)
- Enter the facial features (aka landmarks) that you're interested in. See the diagram below
- Type the address and port of the server (e.g.
localhost:12000) in text field and click Connect
You should already be seeing channels of data about facial features appearing in TouchDesigner. While the width and height
of the video are set to 400x300 (you can change this in index.html if you want to), the values sent to TouchDesigner are always in the range -.5 to .5
This diagram (originally from the clmtrackr repo) shows the numbered coordinates for each of the landmarks. The channel names in TouchDesigner will be "32_x" and 32_y" for landmark #32's x and y coordinates, for example.
If something isn't working, try a different browser. You can also check your browser's console window (F12 on most browsers) to see if there are errors.
If you're seeing data appear in TouchDesigner, but only sometimes, it's important to realize that web browsers normally won't continue sending data if you switch to a different tab in the browser. You can switch away from the browser to TouchDesigner, but you can't switch to a different browser tab.
If the incoming data is slowing down or data appears intermittently, it's possible that your computer isn't up to the task of doing all of this work at once. Or maybe too much data is being sent/received, in which case you should limit the landmarks to only the ones you care about.
If your camera isn't working, make sure that you aren't trying to use it in two places at once. TouchDesigner can't use the camera
at the same time as the browser. Also, make sure you don't have the index.html file open in more than one browser window since they
could both be trying to access the camera at once.
If the browser isn't able to connect to TouchDesigner via WebSockets:
- Use
localhostor127.0.0.1as the IP address - Make sure that the port number is the same in the browser as it is in the Web Server DAT "Port" parameter
- Verify that "Active" parameter is turned ON in the Web Server DAT
This repo is distributed under the MIT License. So is clmtrackr.