Press a key by blinking eyes – Gaze controlled keyboard with Python and Opencv p.8
In this tutorial we’re now going to detect when we press a key by we blink our eyes.
We don’t need to add almost anything new as we already we have the keyboard, or at least one part, and we already wrote the function to detect the blinking.
At the beginning of the script we’re going to create a white image which is going to be the board where we will put the letters we click from the virtual keyboard.
board = np.zeros((500, 500), np.uint8) board[:] = 255
Outside of the loop we create two new variables, one called blinking_frames, and one text. The blinking_frames variable will keep track of the frames in a row in which the eyes are blinking, while text is going to contain all the letter that we will press when we blink our eyes.
blinking_frames = 0 text = ""
Then just after the blinking detection we add +1 to the blinking frames and when the blinking is detected for 5 frames in a row then we add the selected letter to the text.
if blinking_ratio > 5.7: cv2.putText(frame, "BLINKING", (50, 150), font, 4, (255, 0, 0), thickness=3) blinking_frames += 1 frames -= 1 if blinking_frames == 5: text += active_letter else: blinking_frames = 0
Finally we display the text on the board.
cv2.putText(board, text, (10, 100), font, 4, 0, 3)
Now if we want to test our code, we simply need to run it and whenever we want to press a key on the virtual keyboard, we wait that the specific key lights up and then we close the eyes for around a second.
If the key appears on the white window “Board” then the code is working fine.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Gaze controlled keyboard
- Train YOLO to detect a custom object (online with free GPU)
- YOLO object detection using Opencv with Python
- Detecting colors (Hsv Color Space) – Opencv with Python
- How to install Python 3 and Opencv 4 on Windows
- Check if two images are equal with Opencv and Python
- How to install Dlib for Python 3 on Windows
- Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25
- Eye motion tracking – Opencv with Python