How to track left and right hand?

Hi everyone, i am testing hand tracking and following this documentation to track left and right hand

But how can I console.log the detected hand in script? I’ve tried like this (code below) but looks like it didn’t find the hand. Am I doing it wrong?

if (rect_hand0.isTracked === true) {
    Diagnostics.log('Left Hand Detected');
  } else if (rect_hand1.isTracked === true) {
    Diagnostics.log('Right Hand Detected');
  } else if (rect_hand0.isTracked === false) {
    Diagnostics.log('Left Hand Not Detected');
  } else if (rect_hand1.isTracked === false) {
    Diagnostics.log('Right Hand Not Detected');

The isTracked property is of type BoolSignal and so you can’t compare it to a bool like true. Because of the Reactive Programming methodology that Spark uses, you can replace the isTracked with isTracked.pinLastValue() in your code to get the bool value on the frame where you’re running this code.

But also note that if you want to know if a hand is the left hand or if it’s the right hand, it isn’t a simple process. rect_hand0 will be assigned to whichever hand is detected first in the scene, which could be your left hand, your right hand or even the hand of someone whose full body isn’t even in view.

If you need to know left and right, then I think the easiest way is to use 2D Body Tracking and track the wrists

I wouldn’t recommend using pinLastValue because it can do some unexpected things. For these booleans, you can create reactive signals and subscribe to them. This is untested code, but it would look something like this:

rect_hand0.isTracked.eq(true).monitor({fireOnInitialValue: true}).subscribe(() => { Diagnostics.log('left hand detected') })

1 Like