## 4 Methodology: Computer Vision and Deep Learning
### Computer Vision  
The vision module monitors and records body movements during the execution of physical exercises, using the tracking technology provided by Microsoft Kinect v3, which captures a three-dimensional mapping of the user's skeletal structure frame by frame. Each posture is translated into a series of spatial coordinates representing the main joint points. The system relies on skeletal data acquired through Kinect, but these raw data must be interpreted and structured properly. For this purpose, all information regarding the position and orientation of the 20 main joints is stored in XML files, along with additional metadata such as frame number, a unique user ID, and the capture timestamp. Each exercise session generates a collection of these XML files, which are securely stored using a NoSQL database. Before exercises can be performed effectively, the system must be adapted to the user's specific physical features and the surrounding environment, which can vary greatly. The calibration process is divided into two phases:  
1. Initial Motion Analysis: During the initial calibration phase, the system captures a continuous sequence of frames in the first few seconds. Each image is converted to a digital skeleton and saved in an XML file. Based on this dataset, the following joint reference points are identified for each limb involved (Figure 8): - Starting node: the limb joint closest to the trunk of the body (such as the shoulder or hip). - Intermediate node: the central point of the limb (such as the elbow or knee). - Terminal node: the extremity of the limb (such as the hand or foot). Each set of detections produces a series of spatial vectors, from which an average value is computed to represent a reference position for each joint. This strategy improves the reliability of the data by minimizing the impact of temporary tracking errors or minor involuntary movements. Figure 7: ROS2 node structure. Measurement of Limb Lengths: In this stage, the actual length of the user's limbs is calculated using the Euclidean distance formula in 3D space. The length is determined by summing the distances between three key joint points:  
* Distance between the starting node (S) and the intermediate node (I);
* Distance between the intermediate node (I) the and terminal node (T). The exercises considered for the system implementation are those related to the range of motion. Each exercise focuses on a specific part of the body, either upper or lower, which is why the concept of a functional area is introduced: a space within which a particular joint is expected to move during the activity. To identify these areas, during the preparatory phase, a correctly performed exercise by a physical therapist is used as a reference model. The data obtained are then analyzed to understand which joints are involved and what spatial limits define a safe and appropriate range of motion. The identification of relevant joints is carried out through a method inspired by space-time interest points (STIP), an approach often used in computer vision to recognize movements and scenes. The system observes the three-dimensional coordinates of the skeletal joints and selects those that show significant variations over time along one or more axes (\(x\), \(y\), \(z\)). These joints are labeled as significant and subjected to a more detailed analysis to define the area within which they should remain during execution. For example, during the shoulder abduction exercise, the hand trajectory exhibits wide oscillations on the horizontal (\(x\)) and vertical (\(y\)) planes, allowing the limit values for extension and flexion to be easily determined. For the depth (\(z\)) axis, although a constant position is desirable, a tolerance margin (the depth factor) is introduced, defining a range within which the hand can move without compromising the accuracy of the execution.