Beispiel #1
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()
Beispiel #2
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()
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)

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

# Attach the callback manager
predictor.attach_callback_manager(callback_mg)

# Bind all the numbers
for c in ["1","2","3","4","Bow;ing","Push","Pull","Bye-Bye","Drinking"]: