## 3 Algorithm
### Finger Detection
#### 3.2.2 Calculate Finger Angles  
In the palm region, the palm's centroid point and the bottom middle point are denoted as \(P_{c0}\) and \(P_{0}\), respectively shown in Figure 5a. We established a coordinate system on the left bottom corner of the image, so a pixel \(P_{i}\) can be represented as (\(P_{ix}\), \(P_{iy}\)). Afterwards, we define the inclination angle of two points \(<\)\(P_{i}\), \(P_{j}\)\(>\) as follows:  
\[<P_{i},P_{j}>=atan\;2\big{(}P_{yy}-P_{iy},\;P_{jx}-P_{ix}\big{)} \tag{2}\]  
The orientation of the hand is then calculated as (\(<\)\(P_{0}\), \(P_{c0}\)\(>-\pi/2\)). In other parts of the algorithm, this value is by default subtracted from all other angle values to amend the orientation problem. Figure 4: Results of two-phase distance transformation. In (**a**), the green line serves as the boundary for the first distance transformation (DT). The blue line has a distance value of \(d_{in}\). In (**b**), the blue line becomes the second boundary to compute DT. The red line has a value of \(d_{in}\) and is used for separating the palm and fingers. Moreover, the yellow line with a value of \((d_{in}+d_{out})\) is used to exclude non-finger regions. In (**c–f**), another five samples are displayed. Figure 5: (**a**) Hand orientation (green) and region width (red), which is used for estimating finger numbers; (**b**) fingers in a region are separated and located by three points, including a finger point (red circle) at middle, and two finger left and right points (red cross) at sides. In addition, left and right finger boundaries are found and shown in blue. In each finger region, the left and right corners are defined as the points which are on the finger's edge, but one pixel away from the hand edge. Among these points, the one with the largest angle with respect to \(P_{0}\) is considered as the left corner, while the one with the smallest angle is the right corner. The distance between them is used to estimate the number of fingers in this region, which equals to:  
\[n_{i}=\underset{x}{argminx}\cdot\left(\frac{W_{i}}{x}-w_{ave}\right)^{2},\ x\in N ^{*} \tag{3}\]  
where \(n_{i}\) is the number of fingers in the \(i\)th region, \(W_{i}\) is the width of the \(i\)th region, and \(w_{ave}\) is the average width of a finger calculated from the template image. The total number of fingers in this picture equals to \(N=\sum n_{i}\), which are indexed from left to right as 1-\(N\). Then, each finger is enlarged to the palm to obtain the whole finger region, as shown in Figure 5b. They are expanded for four times, each time by three pixels. So, the total extended distance is twelve, which is about twice as \(d_{out}\) to ensure the expansion is complete. The left and right corners are once again located. For the \(i\)th region, a number of (\(n_{i}\)-1) finger corners are uniformly inserted between the left and right corners. Then, between each pair of the adjacent corners, a finger point is inserted, marked in red hollow circles in Figure 5b. All finger angles are indexed from left to right as \(P_{i}\), \(i=1\)-\(N\). The adjacent two corners at the left and right side of \(P_{i}\) are called finger left point \(P_{Li}\) and finger right point \(P_{Ri}\). The angle of the \(i\)th finger is defined as \(A[i]\) which equals to \(<\)\(P_{0}\), \(P_{i}\)\(>\). The finger left and right angles \(A_{L}[i]\) and \(A_{R}[i]\) are defined in the same way. Until now, each finger in the image is detected and described by three angles. The overall procedures are described in Algorithm 1.