## 2 Materials and Methods
### Flowchart of the Control Mechanism for Leg Length Discrepancy Compensation  
The control logic diagram of the LLD compensation mechanism, detailing the entire algorithm--from patient positioning in front of the marker-equipped plane to completion of the artificial limb alignment process--is illustrated in Figure 4.  
Figure 4: Flowchart of the control mechanism for LLD compensation.  
The algorithm commences with the positioning of the prosthetic user, who must assume a predefined stance. The process entails the utilization of markers positioned on the residual limb, the intact limb, and the background surface behind the subject. These markers are subsequently detected by the smartphone camera, facilitating the assessment of LLD.  
The subsequent stage involves the LLD detection process, which is performed by processing the collected data using specially developed algorithms. Once LLD has been identified, the algorithm activates an automated prosthetic length adjustment system to compensate for the discrepancy and restore proper alignment of the artificial limb relative to the contralateral limb.  
The LLD compensation is performed in real time based on feedback from the detection system, while the user receives continuous updates on the process status through a simple and accessible interface. Throughout this process, the user maintains active control over the device, with the ability to manually intervene for additional adjustments or to halt the compensation process if necessary.  
This methodological approach facilitates extensive prosthetic customization, ensuring not only the correction of limb length asymmetries but also the prevention of secondary complications such as joint pain or muscular imbalances, which may arise from misaligned prosthetic devices.  
The subsequent paragraph delineates the image processing steps employed to detect markers and evaluate alignment prior to each compensation step. The smartphone is positioned in front of the mannequin at a distance of approximately 1.5 m and captures real-time images using the IP Webcam Pro(r) application. A leg length discrepancy is then simulated. The system is capable of detecting circular green markers, which are isolated from the background through the application of a segmentation threshold in the HSV (Hue, Saturation, Value) color space. A binary mask is generated to highlight only the green markers. Following the detection stage, morphological dilation operations are applied to enhance the contours. These are followed by the reconstruction of any interrupted regions within the marked area.  
The centers of the detected markers are then connected with virtual lines. A comparison of the initial and final positions of these lines, prior to and following EPM activation, respectively, enables the system to assess the symmetry of the prosthetic user's posture. In the event that the lines are found to be parallel and do not intersect, the adjustment process is halted, as symmetry is deemed to have been achieved. In the event that the lines intersect or are non-parallel, the algorithm identifies the discrepancy as persisting and repeats the compensation step. Each adjustment is followed by a brief delay, allowing for the capture of a new frame and re-evaluation.