Ejemplo n.º 1
0
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = DiscreteSampleManager()

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a classifier
    classifier = SVMClassifier(model_path=args[0])

    # Load the model
    classifier.load()

    # Create a ClassifierPredictor
    predictor = ClassifierPredictor(classifier)

    # Attach the classifier predictor
    manager.attach_receiver(predictor)

    # Create a CallbackManager
    callback_mg = CallbackManager(verbose=True)

    # Attach the callback manager
    predictor.attach_callback_manager(callback_mg)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager(step=20, window=20)

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a threshold middleware
    middleware = GradientThresholdMiddleware(verbose=True, threshold=10, sample_group_delay=5, group=True)

    # Attach the middleware
    manager.attach_receiver(middleware)

    # Also plot the sample
    plotter_mid = PlotterMiddleware()
    middleware.attach_receiver(plotter_mid)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager(window=10, step=5)

    # Attach the manager
    sdr.attach_manager(manager)

    # Create the VerboseMiddleware that prints the received sample
    middleware = VerboseMiddleware(verbose=False)

    # Attach the middleware
    manager.attach_receiver(middleware)

    # Create a predictor
    predictor = HighestAxisPredictor(absolute_values=True)

    # Attach the predictor
    middleware.attach_receiver(predictor)

    # Create a callback manager
    callback_mg = CallbackManager(verbose=True)

    # Attach the callback manager
    predictor.attach_callback_manager(callback_mg)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 4
0
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager(step=20, window=20)

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a threshold middleware
    middleware = GradientThresholdMiddleware(verbose=False,
                                             threshold=40,
                                             sample_group_delay=5,
                                             group=True)

    # Attach the middleware
    manager.attach_receiver(middleware)

    # Create a classifier
    classifier = SVMClassifier(model_path=args[0])

    # Load the model
    classifier.load()

    # Print classifier info
    classifier.print_info()

    # Create a ClassifierPredictor
    predictor = ClassifierPredictor(classifier)

    # Filter the samples that are too short or too long
    lfmiddleware = LengthThresholdMiddleware(verbose=True,
                                             min_len=180,
                                             max_len=600)
    middleware.attach_receiver(lfmiddleware)

    # Attach the classifier predictor
    lfmiddleware.attach_receiver(predictor)

    # Create a CallbackManager
    callback_mg = CallbackManager(verbose=True)

    # Attach the callback manager
    predictor.attach_callback_manager(callback_mg)

    # Attach the callbacks
    callback_mg.attach_callback("knock", receive_gesture)
    callback_mg.attach_callback("doubleknock", receive_gesture)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 5
0
def receive_character(number):
    pyautogui.doubleClick(155, 69)

    if number != "1":
        pyautogui.typewrite(number)
    else:
        pyautogui.keyDown('backspace')
        pyautogui.keyUp('backspace')

    # Create the SerialDataReader
    sdr = SerialDataReader(PORT, expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager()

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a classifier
    classifier = SVMClassifier(model_path=MODEL_PATH)

    # Load the model
    classifier.load()

    # Print classifier info
    classifier.print_info()

    # Create a ClassifierPredictor
    predictor = ClassifierPredictor(classifier)

    # Attach the classifier predictor
    manager.attach_receiver(predictor)

    # Create a CallbackManager
    callback_mg = CallbackManager(verbose=True)

    # Attach the callback manager
    predictor.attach_callback_manager(callback_mg)

    # Bind all the numbers
    callback_mg.attach_callback(" ", receive_character)

    for c in ["1", "2", "3", "4"]:
        callback_mg.attach_callback(c, receive_character)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 6
0
def record_new_samples_piezo(port, gesture_id, target_dir, threshold=5):
    """
    Used to record new samples for the specified gesture_id using a StreamSampleManager and a GradientThresholdMiddleware
    """
    print("RECORDING NEW SAMPLES")

    # Create the target directory if it doesn't exists
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    print("SERIAL PORT:", port)
    print("TARGET DIRECTORY:", target_dir)
    print("GESTURE ID:", gesture_id)
    print("THRESHOLD:", threshold)

    # Create the SerialDataReader
    sdr = SerialDataReader(port, expected_axis=1, baud_rate=74880, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager(step=10, window=10)

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a threshold middleware
    middleware = GradientThresholdMiddleware(verbose=False, threshold=threshold, sample_group_delay=20, group=True)

    # Attach the middleware
    manager.attach_receiver(middleware)

    # Also plot the sample
    plotter_mid = PlotterMiddleware()
    middleware.attach_receiver(plotter_mid)

    # Create a FileGestureRecorder
    recorder = FileGestureRecorder(target_dir=target_dir, forced_gesture_id=gesture_id, verbose=True)

    # Attach the recorder to the manager
    middleware.attach_receiver(recorder)

    # Open the serial connection
    print("Opening serial port...")
    sdr.open()
    print("Opened!")

    print("To exit the loop, press Ctrl+C.")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 7
0
def record_new_samples(port, gesture_id, target_dir, expected_axis):
    """
    Used to record new samples for the specified gesture_id
    """
    print("RECORDING NEW SAMPLES")

    # Create the target directory if it doesn't exists
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    gestures = []

    # If the gesture id is made of multiple gestures separated by a comma, extract them
    if ',' in gesture_id:
        gestures = map(lambda x: x.strip(), gesture_id.split(","))
    else:
        gestures = [gesture_id]

    print("SERIAL PORT:", port)
    print("TARGET DIRECTORY:", target_dir)
    print("GESTURE ID:", gesture_id)

    # Create the SerialDataReader
    sdr = SerialDataReader(port, expected_axis=expected_axis, verbose=False)

    # Create the SampleManager
    manager = DiscreteSampleManager()

    # Attach the manager
    sdr.attach_manager(manager)

    # Create the gesture chooser
    gesture_chooser = RandomGestureChooser(gestures)

    # Create a FileGestureRecorder
    recorder = FileGestureRecorder(target_dir=target_dir, forced_gesture_id=gesture_chooser, verbose=True)

    # Attach the recorder to the manager
    manager.attach_receiver(recorder)

    # Open the serial connection
    print("Opening serial port...")
    sdr.open()
    print("Opened!")

    print("To exit the loop, press Ctrl+C.")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 8
0
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create a simple SampleManager that only prints the received data and signals
    manager = VerboseTestSampleManager()

    # Attach the manager
    sdr.attach_manager(manager)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 9
0
def run_example(*args, **kwargs):
    # Create the SerialDataReader
    sdr = SerialDataReader(kwargs['port'], expected_axis=6, verbose=False)

    # Create the SampleManager
    manager = DiscreteSampleManager()

    # Attach the manager
    sdr.attach_manager(manager)

    # Create the VerboseMiddleware that prints the received sample
    middleware = PlotterMiddleware()

    # Attach the middleware
    manager.attach_receiver(middleware)

    # Open the serial connection
    sdr.open()
    print("Opened!")

    # Start the main loop
    sdr.mainloop()
Ejemplo n.º 10
0
MODEL_PATH="/home/dhwani/Desktop/gesture-keyboard/model.svm"
PORT="/dev/rfcomm0"

def receive_character(number):
    print(number)


# Create the SerialDataReader
sdr = SerialDataReader(PORT, expected_axis=6, verbose=False)

# Create the SampleManager
manager = DiscreteSampleManager()

# Attach the manager
sdr.attach_manager(manager)

# Create a classifier
classifier = SVMClassifier(model_path=MODEL_PATH)

# Load the model
classifier.load()

# Print classifier info
classifier.print_info()

# Create a ClassifierPredictor
predictor = ClassifierPredictor(classifier)

# Attach the classifier predictor
manager.attach_receiver(predictor)
Ejemplo n.º 11
0
def record_new_samples_stream(port, gesture_id, target_dir, expected_axis, threshold=50):
    """
    Used to record new samples for the specified gesture_id using a StreamSampleManager and a GradientThresholdMiddleware
    """
    print("RECORDING NEW SAMPLES")

    gestures = []

    # Create the target directory if it doesn't exists
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    # If the gesture id is made of multiple gestures separated by a comma, extract them
    if ',' in gesture_id:
        gestures = map(lambda x: x.strip(), gesture_id.split(","))
    else:
        gestures = [gesture_id]

    print("SERIAL PORT:", port)
    print("TARGET DIRECTORY:", target_dir)
    print("GESTURE ID:", gesture_id)
    print("THRESHOLD:", threshold)

    # Create the SerialDataReader
    sdr = SerialDataReader(port, expected_axis=expected_axis, verbose=False)

    # Create the SampleManager
    manager = StreamSampleManager(step=20, window=20)

    # Attach the manager
    sdr.attach_manager(manager)

    # Create a threshold middleware
    middleware = GradientThresholdMiddleware(verbose=False, threshold=threshold, sample_group_delay=5, group=True)

    # Attach the middleware
    manager.attach_receiver(middleware)

    lfmiddleware = LengthThresholdMiddleware(verbose=True, min_len=180, max_len=600)
    middleware.attach_receiver(lfmiddleware)

    # Also plot the sample
    plotter_mid = PlotterMiddleware()
    middleware.attach_receiver(plotter_mid)

    # Create the gesture chooser
    gesture_chooser = RandomGestureChooser(gestures)

    # Create a FileGestureRecorder
    recorder = FileGestureRecorder(target_dir=target_dir, forced_gesture_id=gesture_chooser, verbose=True)

    # Attach the recorder to the manager
    lfmiddleware.attach_receiver(recorder)

    # Open the serial connection
    print("Opening serial port...")
    sdr.open()
    print("Opened!")

    print("To exit the loop, press Ctrl+C.")

    # Start the main loop
    sdr.mainloop()