## 5 Deep Learning  
The methodology adopted for the system of detection and correction of rehabilitative movements is divided into several phases: data collection, joint estimation, and movement correction. * Data collection: The images used in the system were extracted as frames from videos belonging to the open-source dataset REHAB24-6 [78]. This dataset contains annotated rehabilitation exercise videos, providing a diverse set of movements focused on upper and lower limb motions. The dataset was built by collecting approximately 2500 images and videos of patients performing common rehabilitative exercises, mainly focused on arm and leg movements such as upper limb rotations, flexions and extensions, lifts, and abductions. The exercises were performed both correctly and incorrectly to enable the model to learn the differences between proper and improper executions. The footage was captured using a high-resolution camera in various environments to ensure good variability in lighting conditions, angles, and clothing types. All images were resized to a fixed resolution of 300 \(\times\) 300 pixels. The dataset was randomly split into a training set (70%) and a test set (30%). * Joint estimation: The system was developed using the Python (version 3.13.4) programming language within the Jupyter Notebook (version 7.4) environment. To estimate the positions of the body's joints, a deep learning model was used--specifically, a modified version of MoveNet Thunder-SinglePose, a pre-trained Convolutional Neural Network designed for human posture analysis. The model, provided by TensorFlow and developed in collaboration with the company Include Health, outputs the coordinates of 17 key body points (such as head, shoulders, elbows, wrists, hips, knees, and ankles) based on RGB images or real-time video streams. * Movement correction: The data obtained from the MoveNet model represent the estimated spatial coordinates of the body keypoints (e.g., head, shoulders, elbows, and wrists) during the execution of an exercise. To assess the correctness of the movement, these estimated coordinates are compared with a set of reference values, which represent the ideal or expected positions of the keypoints based on correctly performed movements. Figure 10: Performance calculation \(P_{\alpha}\). The comparison is based on two fundamental aspects: the distance and the orientation between the estimated keypoints (\(Y_{\text{actual}}\)) and the correct or reference keypoints (\(Y_{\text{correct}}\)). The Euclidean distance between the two coordinate vectors is used to measure the overall spatial difference between the estimated and ideal positions. This distance is calculated as  
\[C=\|Y_{\text{correct}}-Y_{\text{actual}}\|=\sqrt{\sum_{i=1}^{n}(y_{\text{ correct},i}-y_{\text{actual},i})^{2}}\]  
where:  
* \(Y_{\text{correct}}=(y_{\text{correct},1},y_{\text{correct},2},\dots,y_{\text{ correct},n})\) is the vector of the correct keypoint coordinates (e.g., 3D coordinates of head, shoulders, etc. );
* \(Y_{\text{actual}}=(y_{\text{actual},1},y_{\text{actual},2},\dots,y_{\text{ actual},n})\) is the vector of coordinates estimated by the model;
* \(n\) is the total number of coordinates being compared (e.g., 3 for each point in 3D, multiplied by the number of keypoints);
* \(C\) represents the overall deviation measure of the current movement compared to the correct one. A low value of \(C\) indicates that the estimated movement is very close to the reference one and therefore likely performed correctly. Conversely, a high value indicates a significant difference, suggesting an error or deviation in execution. Moreover, the system also considers the relative orientation of the points to ensure not only that small spatial deviations are detected but also that the posture and movement direction are consistent with the expected model. This measure \(C\) is then used as a correction vector that guides real-time feedback to the user, indicating if and how the movement should be adjusted to match the ideal model.