Hi at all, I need to convert cudaImage object to base64 to stream it by websocket, is there a way to do that?
We don’t have a CUDA API for base64 encoding.
But you should be able to find some third party library to convert it into base64.
Please noted that if the encoding is implemented in CPU, you will need to copy the buffer back to CPU first.
First, convert the cudaImage object to numpy array using
cudaToNumpy() function as shown here:
Then, as Aasta mentioned you can use the base64 module to encode the Numpy array:
Hi I solved with this code:
from PIL import Image import base64 from io import BytesIO ## other code img = self.input.Capture() # detect objects in the image (with overlay) detections = self.net.Detect(img, overlay=parameters.model_overlay) # render the image self.output.Render(img) image_array = jetson.utils.cudaToNumpy(img) pil_image = Image.fromarray(image_array, 'RGB') buffered = BytesIO() pil_image.save(buffered, format="JPEG") base64_image = base64.b64encode(buffered.getvalue())
better solutions are welcome!
Thanks for updating your solution with us.
It’s good to know it works.