A very simple gesture recognition technique using opencv and python
Before going on into much details and wasting your time just watch this video to get an idea of what I have done. Here is the first video and the second one. Watch and also follow me :p
Since I am wearing a yellow cap in my fingers, I use that to segment the yellow colour which makes it a lot easier to get the gesture. Here are the steps that I have followed:
- Take one frame at a time and convert it from RGB colour space to HSV colour space for better yellow colour segmentation.
- Use a mask for yellow colour.
- Bluring and thresholding.
- If a yellow colour is found and it crosses a reasonable threshold, we start to create a gesture.
- The direction of movement of the yellow cap is calculated by taking the difference between the old center and the new center of the yellow colour after every 5th iteration.
- The directions are taken and stored in a list until the yellow cap disappears from the frame.
- The direction list is processed and the processed direction list is used to take a certain action.
- Square - Start menu
- Cross - Close
- C - Copy
- A - Select all
- N - Create new file
- V - Paste
- L - Lock the computer
- T - Display task manager
- > - Alt+tab
- < - Alt+Shift+Tab
- <> - Take a photo
- [] - Screenshot
- Square and line - Open text editor
- Since I am using threads in the program the first thing you need to do is go to the site mentioned and apply the solution given. Here is the website https://stackoverflow.com/questions/36809788/importerror-no-module-named-thread
- You need additional imutils functionalities. These can be found here https://github.com/jrosebr1/imutils.
First run the range-detector.py to set the range for the mask for colour segmentation and then press q when the perfect range is found. The easiest way to use it is to put the yellow paper in front of the camera and then slowly increasing the lower parameters(H_MIN, V_MIN, S_MIN) one by one and then slowly decreasing the upper parameters (H_MAX, V_MAX, S_MAX). When the adjusting has been done you will find that only the yellow paper will have a corresponding white patch and rest of the image will be dark. Then start the gesture_action.py. No need to change anything in the gesture_action.py file.
python3 range-detector.py -f HSV -w
python3 gesture_action_ip.py