Hey there, welcome back guys, we are back with another interesting python project with source code – Mouse control with hand gestures using python for you.
Let’s get started…
The title sounds cool, right?
It would be so cool to control your mouse with your hand gestures. Image using your mouse pointer without touching the mouse.
Someone might think you as a magician you can look cool in front of your friends. This is possible by using some image processing concepts, computer vision, and python.
This is my most famous python project in Github that gained popularity with 5 stars and 5 forks. Here is the link to the project.
Watch the demonstration of this python project in Github. Take a look at the consequence of the project if you find it cool you can develop it for yourself.
Work Flow of the project –
The philosophy behind this project is as follows –
- We specify the color range of interest i.e. the color of the glove.
- Using the color range we filter only objects having that color code.
- Next, we select the region of interest. The region with the maximum area in our feed. (This region of interest lies in the color range).
- Now, we associate the mouse controls with the movements of our ROI ( Region of interest, hand in this case).
Steps to run this python project
- Prerequisite( Ignore if you have python) – As a prerequisite, you need python installed in your system. Download the compatible version of python from here.
- Run the following commands in terminal or cmd-
git clone https://github.com/globefire/Hand_detection_tracking_opencv cd Hand_detection_tracking_opencv- pip install -r requirements.txt python hand_detection_tracking.py
Note from the developer(Nitin Sahu): When your palm is open you can move the mouse with your hand gestures. When you form a fist a left click is performed.
Libraries used for this interesting python project
This project uses opencv_python, NumPy, and pyinput libraries. Here is an overview of these libraries.
- opencv_python – This free open-source library developed by intel is used to capture the feed. The feed is very important in the project, you will also need a webcam installed. You can implement the project without webcam too. You need to install the IP Webcam. Comment down in this artice for a detailed explanation.
- NumPy – We use this powerful mathematical library to define kernels. These kernels are essential to filter the region of interest. NumPy is also used to maintain the color range of interest.
- PyInput – This is the cherry of the cake here. We use this library to perform mouse pointer operations like moving it, performing clicks.
Let’s see the explanation of the code now.
Walkthrough of code –
- Importing python modules and creating necessary instances.
We need to create instances of the modules imported to use them. The explanation of instances like kernel Open, kernel Close is mentioned in the script.
2. Capture feed and filter it
Here we detect only regions within the color range of our interest. Then we remove the noises from this region by applying morphology.
And select the region with the maximum area as our controller.
3. Perform mouse operations
After filtering the region of interest, we decide when to move the mouse pointer and when to perform a click.
If the area of our control(our palm) lies in an integer range we consider it as open palm. Else we consider it a first.
I would now conclude the article. Always remember you’ve got an idea? Python a sturdy tool will help you achieve that idea.
I had many ideas and to bring them in real life python has helped me a lot. I have many interesting python projects for beginners in Github that are developed to solve my daily life predicaments.
Thank you for reading this article. If you savored the idea behind this article if you found this article effective do share a word on Facebook, Instagram, LinkedIn.
Also, we would appreciate it if you leave a star on the Github repository it drives people like me to contribute more in the open-source world.
Give your opinions about this Mouse control with hand gestures in python in the comment section.
Also If you have queries regarding this interesting python mini-project, you can write it down in the comment section below.
Feel free to contact us!