Virtual Keyboard 2 – Gaze controlled keyboard with Python and Opencv p.6

We will continue in this section with the creation of the Keyboard.

We’re going to split the keyboard in two parts, so that we will be able to access each part of the keyboard by looking at some specific direction.

For example if we want to access to all the letters that are on the left sides, we just look to the left and the left keyboard will be activated.

Keyboard Left side

As you can see in the keyboard above there are only half of the letters. The second part will contain all the remaining letters, that are placed on the right side of the keyboard.

We’re going first to create a dictionary containing the letters, each one associated with an index.

keys_set_1 = {0: "Q", 1: "W", 2: "E", 3: "R", 4: "T",
              5: "A", 6: "S", 7: "D", 8: "F", 9: "G",
              10: "Z", 11: "X", 12: "C", 13: "V", 14: "B"}

Then we’re going to improve the function that displays the letters on the window.
We will simply pass into this function thress parameters: the letter_index, the letter, and if light up or not the key.

Then in the funcion, for each letter we define the position where we want to display the specific key.

def letter(letter_index, text, letter_light):
    # Keys
    if letter_index == 0:
        x = 0
        y = 0
    elif letter_index == 1:
        x = 200
        y = 0
    elif letter_index == 2:
        x = 400
        y = 0
    elif letter_index == 3:
        x = 600
        y = 0
    elif letter_index == 4:
        x = 800
        y = 0
    elif letter_index == 5:
        x = 0
        y = 200
    elif letter_index == 6:
        x = 200
        y = 200
    elif letter_index == 7:
        x = 400
        y = 200
    elif letter_index == 8:
        x = 600
        y = 200
    elif letter_index == 9:
        x = 800
        y = 200
    elif letter_index == 10:
        x = 0
        y = 400
    elif letter_index == 11:
        x = 200
        y = 400
    elif letter_index == 12:
        x = 400
        y = 400
    elif letter_index == 13:
        x = 600
        y = 400
    elif letter_index == 14:
        x = 800
        y = 400

Finally we can display all the letters looping trough the dictionary we created before, containing the keys of left side of the keyboard.

for i in range(15):
    if i == 5:
        light = True
    else:
        light = False
    letter(i, keys_set_1[i], light)
Blueprint

Learn to build Computer Vision Software easily and efficiently.

This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.

Sign UP for FREE