I am working on a project with interaction using a hand and the kinect chop with a kinect v2.
I require it to work so that if the person 1 hand is not found or if they leave it quickly switches to p2.
By default it seems to remember p1 for a while after they have gone out of frame.
I want people to be able to quickly switch control.
currently I am setting up this up using switches and an execute chop. By checking if the hand is being tracked - using the kinect hand tracked channel - it should switch to the next hand
This is sort of working but as soon as P1 comes back into the scene it jumps back to them. Is there a way to make it stick on hand 2 until it is gone?
I haven’t used while statements in python yet but I’m assuming they are there and that is what I will test now. I’d be curious to know if there is a better way to do this. I often avoid while statements as a lot of my coding is with p5.js or arduino and while statements often cause problems for me in those…
the other way I thought to do this was to have a variable called active hand that changed the address to the control data to select which person is active. before I got to finish that I realised I could use a switch to get the same end result.
This is part of a huuuuge project with many many scenes so I can’t include the original file. I’ve output a test version into this .toe handswitcher.1.toe (1.4 MB)
I’d love any feedback and for now I’m off to test out while statements.
while loops are a bit dangerous in TouchDesigner as python scripts (usually) execute in the main thread holding the TouchDesigner Timeline until the python script has finished.
So for a CHOP approach consider this: We have a bunch of players that enter the screen and we want to interact with the player that has been longest present. So we can count the time the player was on screen and select the player with the longest presence.
Counting time in TouchDesigner can be done via the Count CHOP or also the Speed CHOP. In my example here I will be using the Speed CHOP for simplicity.
Let’s say you have 3 player channels that indicate the presence of somebody here simulated with a Constant CHOP. This is fed into the Speed CHOP. As soon as the channel goes from 0 to 1, the channels in the Speed CHOP will start counting up. The second input to the Speed CHOP is for resetting the count as soon as the channel goes from 1 to 0 (after connecting, set the Reset Condition parameter in the Speed CHOP to “On to Off”). Now if player 2 is being detected, it’s channel will start counting too yet will always have a lower value than player 1 as long as player 1 is being tracked. To get the index of the highest channel value, append a Shuffle CHOP and select “Sequence All Channels” from it’s Method parameter also turning on Use First Sample Only. Now all 3 values are in a single channel and using a Analyze CHOP, you can get the index of the highest value by selecting “Index of Maximum” from the Function parameter. This will be 0 for the first player being the currently tracked one, or 1 for the second player. If nobody is being tracked, this channel will be -1.
Just an extra note: for this to work with the Speed CHOP, make sure the incoming channel is either 0 or 1. Speed increases by the value/framerate over 1 frame meaning it’s increase is dependent from the input value. If you just need something that continuously counts up 1 per frame and the input is not guaranteed to be 0 or 1, have a look at the Count CHOP - the result will be the same.
One more note - just discovered what I believe is a bug (checking on it) but currently if all values are the same, the Analyze CHOP will return the index of the last sample in it’s input. So no -1 indicator for when no player is tracked. To counteract this, merge in an additional channel with a value of 0 before going into the Shuffle CHOP. Now when no player is tracked, the value of the analyze will be equal to that channel’s index.
Amazing Markus! yes that makes sense
Thanks for the help. I think after this I need to spend some serious time learning more about the different chops and how to turn programming into operators. I’m more used to coding interaction so keep falling back on that but I see the value in doing logic in chops.