## 2 Materials and Methods
### The proposed Motion Analysis System
#### 2.1.2 Parameter Calculation  
This module, developed in Python, uses the C++ output from the Data Collection module to determine the person orientation with respect to the camera(s) and to calculate the 2D angles between the respective body segments. The angles between the body segments are evaluated according to the predicted orientation. For each frame, they are computed from the coordinates (x, y) of the respective keypoints, by using proper algorithms. To estimate the angle between the segments i-j and j-k (considering the coordinates of the keypoints i, j and k) the following formulas are applied:  
\[\theta=\left(\arccos\left(\frac{\gamma}{\delta}\right)\right)\times\left(\frac {180}{\pi}\right) \tag{1}\]  
where \(\gamma\) is the scalar product between the vector formed by the first cathetus (i-j) and the one formed by the second cathetus (j-k) and \(\delta\) is the cross product between the norms of the aforementioned vectors:  
\[\gamma=\left(\mathrm{x_{j}}-\mathrm{x_{i}}\right)\times\left(\mathrm{x_{k}}- \mathrm{x_{j}}\right)+\left(\mathrm{y_{j}}-\mathrm{y_{i}}\right)\times\left( \mathrm{y_{k}}-\mathrm{y_{j}}\right) \tag{2}\]  
\[\delta=\left(\left|\sqrt{\left(\mathrm{x_{j}}-\mathrm{x_{i}}\right)^{2}+\left( \mathrm{y_{j}}-\mathrm{y_{j}}\right)^{2}}\right|\right)\times\left(\left| \sqrt{\left(\mathrm{x_{k}}-\mathrm{x_{j}}\right)^{2}+\left(\mathrm{y_{k}}- \mathrm{y_{j}}\right)^{2}}\right|\right) \tag{3}\]  
In the case of two cameras, it is necessary to consider that one camera among all will have the best view to predict some angles correctly: to this end, a special algorithm has been developed. Considering that the cameras are positioned at about the pelvis height, it performs a comparison between the distances interposed between the key points (corresponding to specific body segments) and the expected average anthropometric proportions of the human body reported in [55], which are calculated on a large dataset of individuals. In particular, it analyzes the ratio between the width of the shoulders (i.e., Euclidean distance between key points 2 and 5) and the length of the spine. The Euclidean distance between the key point 1, and the midpoint (m), between key points 8 and 11, is considered to estimate the spine length since the CMU model does not consider a pelvis key point. Based on the human body proportions reported in [55], such a ratio is estimated equal to 80%, when the subject is in front of the camera, and to 0% when the person turns at 90\({}^{\circ}\). Consequently, the angle between the sagittal plane of the person and the direction of the  
Figure 2: tf-pose-estimation CMU model: acquired joints of body. camera (\(\alpha\)) can be estimated through the following equation, considering the length of the segments related to shoulder (x) and spine (l) measured in each frame:  
\[\alpha=\arcsin\Big{(}\frac{\mathrm{x}}{1\cdot 0.8}\Big{)} \tag{4}\]  
To determine whether the camera is framing the person's right side or left side, the x coordinate of the key point \(0\), \(\mathrm{X}_{0}\), has been considered in relation to the average x coordinate of keypoints 1, 2, and 5, \(\mathrm{X}_{a}\). The person's side framed by the cameras is then determined according to the following algorithm:  
\[\mathrm{X}_{0}-\mathrm{X}_{a}\bigg{\{} \begin{array}{l}<0,\text{ left}\\ >0,\text{ right}\end{array}  \tag{5}\]  
In case two video shots are available, recorded from angles settled at 90\({}^{\circ}\) to each other (e.g., respectively parallel to the frontal and the sagittal planes), it is then possible to refer the orientation estimation to a single reference system, using as origin the direction of the first camera (camera index 0). The compute of each angle is then performed considering the frame coming from the camera view that better estimates it.