Table of Contents

Finger Tracking – Python

Example Description
The example demonstrates how to use hand recognition to track the different parts of the fingers in Python Coding Environment.

Code

thumb = Sprite('Thumb')
index = Sprite('Index')
middle = Sprite('Middle')
ring = Sprite('Ring')
pinky = Sprite('Pinky')

hand = Posenet()
hand.video("on", 0)
hand.enablebox()

thumb.switchcostume("ball-a")
thumb.setsize(50)
index.switchcostume("ball-b")
index.setsize(50)
middle.switchcostume("ball-c")
middle.setsize(50)
ring.switchcostume("ball-d")
ring.setsize(50)
pinky.switchcostume("ball-e")
pinky.setsize(50)

while True:
  hand.analysehand()
  
  if hand.ishanddetected():
    thumb.setx(hand.gethandposition(1, 4))
    thumb.sety(hand.gethandposition(2, 4))
    thumb.show()
    
    index.setx(hand.gethandposition(1, 8))
    index.sety(hand.gethandposition(2, 8))
    index.show()
    
    middle.setx(hand.gethandposition(1, 12))
    middle.sety(hand.gethandposition(2, 12))
    middle.show()
    
    ring.setx(hand.gethandposition(1, 16))
    ring.sety(hand.gethandposition(2, 16))
    ring.show()
    
    pinky.setx(hand.gethandposition(1, 20))
    pinky.sety(hand.gethandposition(2, 20))
    pinky.show()
  
  else:
    thumb.hide()
    index.hide()
    middle.hide()
    ring.hide()
    pinky.hide()

Output