I have a piece of python code that generates an image. This works, but now I would like to send that image directly to a TOP.
I can only get it working by saving it first as a PNG file and then loading that file back in. Is there a more direct way to show the image without saving it first?
My code
import qrcode
print("imported qrcode")
img = qrcode.make('https://test.nl')
# this works
img.save("myfile.png")
op('moviefilein1').par.file = "myfile.png"
# but I need something like this
op('moviefilein1').par.file = img
Thanks, but I was wondering if you can’t just send any image generated with python, straight into a TOP?
I don’t need to save the image, just display it until the next image is generated in python.
To put it differently:
# generate an image
img = myCoolFunction.generateImage()
# send it to a TOP
op('moviefilein').showImage(img)
It is possible, but the question is if it is neccesarry.
In theory you can convert the pillowImage that is returned from the make-function into a numpyArray.
The scriptTop has a copyNumpyArray method to load the values of the numpy-array directly in to a top.
But the np-array you get from the image is in the wrong format and at that Point I just used the 5 lines of code I already had.
TouchDesigner scriptTOP requires 3 channels in the numpy array. The qrcode library returns an image with only a single luminance channel. So we need to convert the qr_image to RGB before creating a numpy array.
Create a scriptTOP and open its callbacks DAT. Replace its content with the following: