Retrieving numpy representation in lua

Hi all, I hope you are all doing good

My application workflow when any new instance is added to Orthanc, Lua script is revoked and sent the instance id and numpy representation of the pixel data of the DICOM file to my fast API server which is interface with my AI model so I can eventually create a mask of this DICOM file.

I am now having a problem that the return value from the numpy API call inside lua is string and equal to “\u04ceUMPY\u0001” which you can find printed inside the attached Orthanc log, this is incorrect as I use the same API call using python and the content of the body of the request was of type which I can easily convert to normal image format, but now I don’t know how to convert this string format to an image format when I received in my server, so any proposed solutions are really appreciated

I am calling numpy API inside lua because when I use it inside my fast API server and lua only sends the instance id, the whole operation was done in 1 minute which is very expensive.
I tried to test which part is time-consuming so I stopped lua and sent the instance id manually to my fast API endpoint, and the whole process takes max 4 sec.
So I conclude that when I call Orthanc rest API inside an endpoint that communicates with lua I got this delay like mentioned in Orthanc lua concurrency-and-deadlocks.

I am open to any solutions that can fit my workflow and I can effectively send the numpy representation of the pixel data of the DICOM file to my AI Model.

Thanks in Advance.

Orthanc log (3.06 KB)

Lua Script (468 Bytes)

I have solved the problem I posted by using python script instead of lua, as far as I know, lua can’t handle with bytes array which resulted from the numpy API call, So I find out that python plugin has also event that can be revoked once a new instance had been uploaded to orthanc which just like I want.
This helps me solve also the 1-minute delay in my application for waiting for the response of orthanc API call in my fast API server after communication with lua.
This problem doesn’t occur when I used the python plugin, so now my whole process is done in about 3 seconds including my AI prediction.
You can find attached my logs stating the time differences between using lua and python script.
And the python script I used to solve the problem

Python Script (741 Bytes)

Fast API logs (1.34 KB)