Convert cudaImage to base64

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.

For example:

Please noted that if the encoding is implemented in CPU, you will need to copy the buffer back to CPU first.


1 Like

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:

1 Like

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 =, overlay=parameters.model_overlay)

# render the image

image_array = jetson.utils.cudaToNumpy(img)

pil_image = Image.fromarray(image_array, 'RGB')

buffered = BytesIO(), 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.