Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df98201

Browse files
Update README.md
1 parent 6aa52be commit df98201

File tree

1 file changed

+0
-112
lines changed

1 file changed

+0
-112
lines changed

‎README.md‎

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1 @@
1-
> for people using python2 and opencv2, please check out the [`lzane:py2_opencv2`](https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/tree/py2_opencv2) branch.
2-
3-
> for people using opencv4, please change line 96 in the `new.py` to `contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)` according to the [opencv api change](https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/issues/7#issuecomment-509925971).
4-
5-
6-
## Environment
7-
- OS: MacOS El Capitan
8-
- Platform: Python 3
9-
- Librarys:
10-
- OpenCV 3
11-
- appscript
12-
13-
14-
## Demo Videos
15-
- Youtube: [Click here](https://youtu.be/CmBxUnp7XwM)
16-
- Youku: [Click here](http://v.youku.com/v_show/id_XMTc3MjI4MjQwOA==.html)
17-
18-
## How to run it?
19-
- run it in python
20-
- press `'b'` to capture the background model (Remember to move your hand out of the blue rectangle)
21-
- press `'r'` to reset the backgroud model
22-
- press `'ESC'` to exit
23-
24-
## Process
25-
#### Capture original image
26-
27-
Capture video from camera and pick up a frame.
28-
29-
![Alt text](material/-1474508814843.png)
30-
31-
#### Capture background model & Background subtraction
32-
Use background subtraction method called **Gaussian Mixture-based Background/Foreground Segmentation Algorithm** to subtract background.
33-
34-
For more information about the method, check [Zivkovic2004](http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf)
35-
36-
Here I use the OpenCV's built-in function `BackgroundSubtractorMOG2` to subtract background.
37-
38-
```python
39-
bgModel = cv2.BackgroundSubtractorMOG2(0, bgSubThreshold)
40-
```
41-
42-
Build a background subtractor model
43-
44-
45-
46-
```python
47-
fgmask = bgModel.apply(frame)
48-
```
49-
Apply the model to a frame
50-
51-
52-
```python
53-
res = cv2.bitwise_and(frame, frame, mask=fgmask)
54-
```
55-
56-
Get the foreground(hand) image
57-
58-
![Alt text](material/-1474508613267.png)
59-
60-
#### Gaussian blur & Threshold
61-
```python
62-
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
63-
```
64-
First convert the image to gray scale.
65-
66-
```python
67-
blur = cv2.GaussianBlur(gray, (blurValue, blurValue), 0)
68-
```
69-
By Gaussian blurring, we create smooth transition from one color to another and reduce the edge content.
70-
71-
![Alt text](material/-1474508640877.png)
72-
73-
```python
74-
ret, thresh = cv2.threshold(blur, threshold, 255, cv2.THRESH_BINARY)
75-
```
76-
We use thresholding to create binary images from grayscale images.
77-
78-
![Alt text](material/-1474508661044.png)
79-
80-
81-
#### Contour & Hull & Convexity
82-
We now need to find out the hand contour from the binary image we created before and detect fingers (or in other words, recognize gestures)
83-
84-
```python
85-
contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
86-
```
87-
This function will find all the contours from the binary image. We need to get the biggest contours (our hand) based on their area since we can assume that our hand will be the biggest contour in this situation. (it's obvious)
88-
89-
After picking up our hand, we can create its hull and detect the defects by calling :
90-
```python
91-
hull = cv2.convexHull(res)
92-
defects = cv2.convexityDefects(res, hull)
93-
```
94-
95-
![Alt text](material/-1474508788185.png)
96-
97-
98-
Now we have the number of fingers. How to use this information? It's based on your imagination...
99-
100-
I add in a keyboard simulation package named **appscript** as interface to control Chrome's dinosaur game.
101-
102-
![Alt text](material/-1474522195081.png)
103-
104-
----------------------
105-
## References & Tutorials
106-
107-
1. OpenCV documentation:
108-
http://docs.opencv.org/2.4.13/
109-
2. Opencv python hand gesture recognition:
110-
http://creat-tabu.blogspot.com/2013/08/opencv-python-hand-gesture-recognition.html
111-
3. Mahaveerverma's hand gesture recognition project:
112-
[hand-gesture-recognition-opencv](https://github.com/mahaveerverma/hand-gesture-recognition-opencv)
1131

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /