Ever wondered about playing Subway Surfers with your body movements! I have made a program to synchronize basic body movements with movements in games like Subway Surfers, Temple Run, etc.
I have made the program in python using OpenCV
(for video and movement detection) and pynput
(for keyboard actions).
Follow the following instructions to run the code on your local machine.
Install this package using:
pip install opencv-contrib-python
In case the code shows any error try installing:
pip install opencv-python
Install this package using:
pip install pynput
You can download the game from anywhere. There are a lot of options present but some of them might not work. I have used Bluestacks to run Subway Surfers.
Laptop cameras generally do not have good quality. So I have used Droid Cam to use my mobile camera as a webcam to get a better frame rate and accuracy. If you are doing this then make sure to change the argument of the cv2.VideoCapture(0)
to 1
in line number 5.
After running the code, a window will open. Make a box-like structure(called bounding box) keeping its midpoint on the part of the body to be detected(in my case: tip of nose).
Press Enter and a small circle will appear around that part. Now if you move out of the circumference of the tracking circle, the terminal shows where are you moving. Now start playing the game and move as you want the player to move. HAPPY PLAY!
You can always set some parameters according to your convenience:
1)Tracking Circle(outer circle): tracking_circle_radius
in line number 27
2)Detection Circle(inner circle): detection_circle_radius
in line number 66
3)There are 8 trackers available. MedianFlow
works best for me as it provides good accuracy as well as FPS but you can try all of them, as each one has different FPS and accuracy with diffrent sizes of bounding boxes.
You can run the code on any IDE but my VSCode was giving some issue so I recommend using PyCharm.
Try to keep the camera away from the light as reflection hampers the tracking.
Try to avoid unnecessary movement as the detection circle might displace from its desired position.
The program is not very efficient. It may take you time to get acquainted.
Sahil Ahuja