## 4 Results
### Image Processing with OpenCV
#### 4.3.3 Simultaneous Run of Both Algorithms  
As a final evaluation, the two computer vision algorithms described above were implemented in a whole simulator run aimed at detecting both the blue colour and the face of a moving avatar. For it, the two possible ways of operating with various types of image processing algorithms on the same image were implemented. The first consisted of running the algorithms sequentially, either from C++ or Python. The second option was to run the image processing algorithms in parallel in different programs. The latter option would have a great advantage in terms of performance, although, in this case, it could only be implemented using MQTT. Indeed, thanks to the use of MQTT, several programs can run at the same time, all receiving the same image but processing it in different threads. However, with the native C++ plugin, each algorithm would necessarily have to run after the other (sequentially) in the same Unity simulator thread. Both Algorithms Running in the Same Program  
Figure 10 describes how the colour and face detection algorithms were executed sequentially in C++ and Python. Image processing occurs in the native plugin through a call to a DLL function within the execution flow of the simulator. Metrics are evaluated from the time an image is captured until the function returns the processing result. In contrast, data are sent to and received in Python through the MQTT protocol without interfering with the execution flow of the simulator. As can be seen in Figure 10, the function call is synchronous. Therefore, the simulator cannot continue processing until the function returns a value. On the other hand, MQTT provides an asynchronous communication flow, and this means that Python processes the incoming images independently of Unity's execution flow. This will result in faster communication, processing and data feedback time. The significant difference between a plugin and MQTT is shown in Figure 11. Although the times were individually quicker in C++, the interoperability offered by MQTT demonstrates better performance in the communication, processing and value returning flow. C++ showed performance in the range of 40 to 65 ms, while MQTT with Python exhibited performance of 13 to 26 ms. This is almost three times faster than the native plugin processing synchronously on the same thread. This finding is also confirmed when comparing the average processing time in the conducted test. The processing time given for Python is 16.30 ms on average versus more than 43.38 ms for C++. Figure 10: Sequential execution of colour and face detection algorithms: (**a**) C++ DLL, (**b**) Python program communicated via MQTT. Both Algorithms Running in Different Programs (MQTT Only)  
MQTT allows work to be distributed across separate programs providing asynchronous and independent communication. Figure 12 shows a diagram of how a distributed processing system would work in this study. The colour and face detection algorithms ran in two independent programs to evaluate that distributed system (see Figure 13). The two algorithms were executed in separate Python scripts, each exclusively performing its own processing and transmitting the results via MQTT to Unity. It was necessary to add an additional listening channel to differentiate the messages from each of the programs. The graph of the total processing time revealed a higher computational load of the face detection algorithm compared to the colour detection algorithm, which is obvious. What is relevant in this case is the advantage that Python offers in being able to distribute the load between two programs (or even more if necessary in other more complex developments). In contrast, in C++, it is not possible to build a distributed system through the communication of native plugins. Even if several native plugins were to be developed, each with different processing, function calls would be synchronous. Figure 11: Complete processing times of the colour and face detection algorithms in C++ and Python.