Problem :
Many disabled gamers face significant obstacles when trying to access and enjoy digital gaming, resulting in limited opportunities for entertainment, social interaction, and skill development. Traditional gaming interfaces are often ill-suited to their specific needs, creating a barrier to their full participation in the gaming community. This exclusionary aspect of gaming for disabled individuals highlights the urgent need for an innovative solution that enhances accessibility and inclusivity in the gaming world.
Solution :
This solution is a groundbreaking, PC-based system that empowers disabled gamers to play Tetris on tetr.io using customizable gesture controls. The best part - It's free! By utilizing Teachable Machine and a camera (webcam or your phone camera), it enables players to define their own gesture poses, seamlessly integrating with any computer setup. This innovative approach promotes inclusivity and empowers disabled gamers to overcome traditional interface limitations, fostering social engagement and skill development within the gaming community.
Result :
At the end of this tutorial, you will have yourself a fully working system, that will enable you to play Tetr.io with your face, mouth, or any other movements. You will be able to participate in multiplayer and solo Tetris games! I gave this code to my disabled friend, and he appreciated it a lot. He said that he could game like this for hours and all of the time he was immersed and had a lot of fun.
I set this model to move blocks with a smile and a sad face. This method of control is really engaging and would be fun even for kids.
Also, you will learn a simple and fun way to train an AI model yourself!
Demo videoBefore we startBefore creating the AI model we have to install Python and some libraries for this code to work.
First of all - Let's install python! Here's the link. Click "download python" and when installing check the "Add python.exe to PATH" and then press "Customize installation". Also, check if the "pip" is checked. In the next step also check "Add Python to environment variables" and install.
When Python is installed - open your command prompt and type in the following commands to install all the necessary libraries (each line separately) :
pip install teachable-machine
pip install opencv-python
pip install pyvirtualcam
pip install pynput
Connecting a cameraIf you have a webcam - awesome, but for those who don't, you don't need to spend money! You can just your phone as a webcam because nowadays most smartphones already have an amazing camera. To connect your phone's (android/ios) camera to pc I recommend trying out this app. Just install it on both pc and your phone.
Now you have to download all the necessary code for this project! You can find all the files below or in my GitHub repository. Now you have to choose how are you going to control the game! I have prepared 2 methods. One is face recognition and the other is only mouth. I chose the face. Or if you need to control your, for example, arms, you can also do that. If you won't use your face or mouth - go to the next step "Training the AI model".
Now if you choose face or lips, you need to use the CamSimFace.py or CamSimLips.py script. These scripts make a "virtual" camera from your actual web or phone camera. The virtual camera zooms into your face/mouth and makes the image grayscale, so it's easier for the model to understand your facial expressions in any lighting condition and background.
Before running the scripts, you have to download OBS, and also you have to change a line in the CamSim...py script. You can use Notepad or any code editor to open the script, without running it :
cap = cv2.VideoCapture(0)
You have to change the number in the brackets. The number represents your original camera port. Usually, the main camera is in port 0, but to check you can use cameraPortTest.py. When you run it, it will open windows with the available cameras and show what port is all of them using. Now, when you change the number, you can run the CamSim....py code and proceed to the next step.
Training the AI modelFor the AI we are going to use Google's "teachable machine". Open the webpage and click "Get Started".
Also, you can choose to control the game with a pose, but for the face/mouth you have to use "Image Project".
Now you have to train the model. Add 4 classes and label them - 1 "Normal", 2 "Left", 3 "Right", and 4 "Rotate". Now you have to click on the "Webcam" button and open the camera you are going to use (Main or Simulated). You have to capture about 200 pictures for each box. In the "Normal" you have to relax your face/mouth/body/arm/... to the normal position and capture the images. For left, right, and rotate you need to create unique poses and capture them.
I made mine like this. I set Left to smile, Right to sad, and Rotate without lips.
The model will be more precise and accurate, without fail, if you take a lot of pictures.
After you have done that and Trained the model, you have to check if it is accurate. You can do that by checking the "Preview" window, if when you make those expressions/poses it shows the right output as 90 - 100% without errors. If it can't recognize and moves around a lot, you have to remake the model or create different expressions.
When you have checked, that the model works fine, you can proceed and click the "Export Model" button. You have to choose TensorFlow -> Keras -> Download my model. And wait while it downloads.
When everything is downloaded, you can unzip the model and copy both the.h5 and the.txt files to the folder, where you have my code.
Configuring Main.pyNow, we have to do the last step, configure in which folder is the model and text file. Open the Main.py with a text editor and change these lines to the right folder. There is an example of how to do that, replace it with your own.
model_path = "C:\\Users\\Admin\\Desktop\\keras_model.h5"
labels_path = "C:\\Users\\Admin\\Desktop\\labels.txt"
You can also change the countdown timer (to start the game, before the script starts).
countdown_seconds = 30
Using the codeNow, when we have finished the set-up, we can start playing Tetris! First, you can download the ter.io client or play it online. To start practicing, go to Solo -> Zen -> Start, in the right side you can access the settings and set the gravity to "relaxed".
Now you can run the Main.py script. It will open a window and give you 30 seconds to open tetr.io and start a game. After 30 seconds it will start and you will be able to control it with gestures.
Comments