## 3 Algorithm
### Finger Angle Prediction  
The proposed algorithm requires one template image for each person to implement the template matching. The template is the gesture \"Five\", as shown in Figure 6a, whose five stretched fingers are detected and calculated using the method described above. The five types of fingers are indexed from the thumb to the little finger as 1 to 5. For the \(i\)th finger, its finger angle is noted as \(A_{T}[i]\), and the left and right finger angles are \(A_{TL}[i]\) and \(A_{TR}[i]\) respectively, where \(i=1\)-5. We represent a gesture using a five-element tuple \(Y\). If the \(i\)th finger type exists in the gesture, \(Y[i]\) equals 1, otherwise 0. For the template gesture, \(Y_{T}\) equals [1, 1, 1, 1, 1]. For an unknown gesture with \(N\) fingers, \(Y\) could be \(M\) possible values corresponding to \(M\) different gestures, where \(M\) equals to:  
\[M=\frac{\prod_{k=1}^{N}(5-k+1)}{\prod_{k=1}^{N}k} \tag{4}\]  
We denote the \(j\)th possible gesture as \(Y_{j}\). In order to compare \(Y_{j}\) with \(Y_{T}\) to determine which candidate is most similar to the template, we calculate the five finger angles of \(Y_{j}\), named as \(A_{Ej}[i]\), \(A_{Ej}[i]\), \(j=1\)-\(M\), and \(i=1\)-\(5\). These five fingers are defined as extended fingers, where \(N\) of them are already known, and the remaining (5-\(N\)) ones are predicted using the following method. If \(Y_{j}[i]\) equals 1, then this finger is already known. If \(Y_{j}[i]\) equals 0, then this finger needs to be hypothetically inserted near the known fingers. The insertion works as such: if several fingers are inserted between two known fingers, they are uniformly distributed between the two. If several fingers are added at the left of the leftmost finger, then the gap between each pair of fingers equals to the corresponding one in the template gesture. So too does the case of inserting fingers to the right. Moreover, for the left and right angles of an inserted finger with the \(i\)th index, the difference between them is equal to the corresponding \(i\)th finger in the template. The detailed implementation is described in Algorithm 2. ```
function\(A_{E}\), \(A_{EL}\), \(A_{ER}\) = Finger prediction(\(A\), \(A_{L}\), \(A_{R}\), \(A_{T}\), \(A_{TL}\), \(A_{TR}\), \(Y\)) # \(A[N]\): N known finger angles of the image. # \(A_{T}[5]\): Five finger angles of the template gesture \"Five\". # \(Y[5]\): Five binary elements representing a possible gesture of the image. # \(A_{E}[5]\): Five extended finger angles under the case of \(Y[5]\). # Step 1. Initialize known fingers \(A_{E}\) = [0, 0, 0, 0, 0] \(\mathrm{Index}_{\mathrm{knownFingers}}\) = find(\(Y[5]\) = 1) # e.g., \(Y\)=[0, 1, 0, 0, 1], return [2,5]; \(A_{E}[\mathrm{Index}_{\mathrm{knownFingers}}]\) = \(A\) # Step 2. Predict fingers on the left for\(i=\min(\mathrm{Index}_{\mathrm{knownFingers}})\) - 1 to 1 step -1 \(A_{E}[i]\) = \(A_{E}[i+1]\) + (\(A_{T}[i]\) - \(A_{T}[i+1]\)) # Step 3. Predict fingers on the right for\(i=\max(\mathrm{Index}_{\mathrm{knownFingers}})\) + 1 to 5 \(A_{E}[i]\) = \(A_{E}[i-1]\) + (\(A_{T}[i]\) - \(A_{T}[i-1]\)) # Step 4. Predict fingers which are inserted between the two for\(i=1\) to length (\(\mathrm{Index}_{\mathrm{knownFingers}})\) - 1 \(\mathrm{Ind}_{\mathrm{Left}}\) = \(\mathrm{Index}_{\mathrm{knownFingers}}[i]\) \(\mathrm{Ind}_{\mathrm{Right}}\) = \(\mathrm{Index}_{\mathrm{knownFingers}}[i+1]\) for\(j=\mathrm{Ind}_{\mathrm{Left}}+1\)to\(\mathrm{Ind}_{\mathrm{Right}}\) - 1 \(A_{E}[j]\) = \(A_{E}[j-1]\) + (\(A_{E}[\mathrm{Ind}_{\mathrm{Right}}]\) - \(A_{E}[\mathrm{Ind}_{\mathrm{Left}}]\)) \(\times\) (\(j\) - \(\mathrm{Ind}_{\mathrm{Left}}\)) / (\(\mathrm{Ind}_{\mathrm{Right}}\) - \(\mathrm{Ind}_{\mathrm{Left}}\)) # Step 5.