Actually, I was a little poor in the description because I thought I shouldn't bore you.
Let's see if I can group the ideas.
1] The IP Camera
The IP camera is made with an embedded board + a motorized camera sensor + Linux.
The IP camera, mounted on the Z axis of the CNC, uses a LAN connection to receive commands (eg: manual focus, brightness, resolution, etc)
and return a stream of encoded and compressed frames.
To do this, it uses the TCP / UDP protocols.
The management software was initially made with Python but then I will calmly rewrite it completely in C ++.
Theoretically, the code is already performing even in Python, as the bottleneck remains the acquisition of the frames from the sensor,
their encoding, and compression, which is already done using native code libraries.
In any case, a large part of the Python project was then compiled with Cython, creating python modules .so that a few percentage points of profit made me get.
2] Delphi and its expansion modules for Python.
Initially, I tried to manage TCP/UPD streams directly in Python via sockets and threads, but unfortunately, Python gives the worst,
as threading management is always subject to the rules of the GIL and therefore in fact creating more threads in python does not always
mean being able to optimize the use of cores.
I will not dwell on this question, which I too was not aware of, there are many discussions on the net.
I, therefore, thought of using Delphi to create an extension module for Python in which I entered all the communication work between PC and
Camera using Delphi's TThread (more practically internally I used INDY both for the TCP Client and for the UDP server)
In python, I no longer needed to create threads for managing TCP/UDP packets with the resolution of many problems that I had had in the first tests.
Still in the Python expansion module written in Delphi, I was able to manage other features not present in ready-made libraries for Python,
but which I already had working fine in Delphi, certainly gaining performances.
3] Python program
The Python program is actually made up of Python + DelphiVCL + Skia + OpenCV and other minor libraries, plus an image processing framework
that I built from scratch in pure python language.
To improve performance, the whole package, apart from the main file, was also compiled with Cython, obtaining a series of .pyd modules that make up the final product.
4] CNC
The CNC is actually made up of an embedded board with a REAL TIME industrial operating system that I wrote years ago and that we have been using for years
for CNC and PLC and all the CNC part is done directly on the board.
The CNC board, which controls the motors/inputs/outputs/EtherCAT /etc, communicates with the PC and with the CNC control software via LAN.
The control software is just a UI interface, has a G-code compiler, and takes care of transferring motion instructions or pre-processed blocks to the CNC board's execution buffer.
In the CNC control software, there is an API server (TCP/Server) which allows an external program/process, through an API Client, to access all the functions of the CNC,
including sending programs, MDI programs, JOG, etc.
So for Python, I have created a package that implements the client core API allowing a Python program to have full control of the CNC.
NOTE
The program can use Themes.
Without a theme, the assignment of a Bitmap to TImage objects (a Window control) can generate flickering (due to the WM_ERASExxx message).
Using Themes the flickering increase a lot.
So I've created a new DelphiVCL branch with Graphics32:TImgView32 which is a TGraphicControl-based object and solved the flickering phase managing the PAINT event.
Now I've been really boring :)
Sorry!