Hi,
I have the following code in python :
import sys, _thread, time,cv2, math, ctypes
import Leap
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
import numpy as np
import telnetlib
import socket
import subprocess
import os
class SampleListener(Leap.Listener):
finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE_INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
def on_init(self, controller):
i=1
#print("Initialized")
def on_connect(self, controller):
#print("Connected")
# Enable gestures
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
#controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
#controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP);
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
controller.config.set("Gesture.Swipe.MinLength", 100)
controller.config.set("Gesture.KeyTap.HistorySeconds", 0.1)
controller.config.save()
def on_disconnect(self, controller):
# Note: not dispatched when running in a debugger.
d=1
#print("Disconnected")
def on_exit(self, controller):
e=1
#print("Exited")
def leap_hand_type(self,controller):
global clock
global l_string
l_string=0
clock=0
prev_frame = controller.frame()
global tot_hands
tot_hands=len(prev_frame.hands)
global ver_leaphands,hor_leaphands,depth_leaphands
ver_leaphands = 0
hor_leaphands = 0
depth_leaphands = 0
if (tot_hands>0):
for hand in current_frame.hands:
for gesture in prev_frame.gestures():
if gesture.type == Leap.Gesture.TYPE_CIRCLE and Leap.Gesture.STATE_START and gesture.state != Leap.Gesture.STATE_UPDATE and gesture.type != Leap.Gesture.TYPE_INVALID:
circle = CircleGesture(gesture)
# Determine clock direction using the angle between the pointable and the circle normal
if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/2 and circle.progress >= 1:
clockwiseness = "clockwise"
elif circle.pointable.direction.angle_to(circle.normal) > Leap.PI/2 and circle.progress >= 1:
clockwiseness = "counterclockwise"
else:
clockwiseness = "INVALID"
if circle.state != Leap.Gesture.STATE_START and circle.state != Leap.Gesture.STATE_UPDATE:
if clockwiseness!= "INVALID":
if clockwiseness == "clockwise":
clock = 1
elif clockwiseness == "counterclockwise":
clock = 2
else:
clock = 0
else:
sys.exit()
return tot_hands
def on_frame(self, controller):
self.leap_hand_type(controller)
def main():
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()
>
# Have the sample listener receive events from the controller
leap_s = controller.add_listener(listener)
print(leap_s)
# Keep this process running until Enter is pressed
#print("Press Enter to quit...")
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
# Remove the sample listener when done
controller.remove_listener(listener)
if __name__ == "__main__":
main()
I wanted to get the tot_hands value out to the main function so that I can read it from the sys.line . Is there any way to do it?