How can I display an Nvidia vpi Image in GPU memory?

How can I display an Nvidia vpi Image in GPU memory?
I’m doing some operations in nvidia vpi image. Then for display I need to download it back to cpu memory.
Is there a way I can display it in vpi Image format itself without bringing it back to cpu?

Here’s my sample code

import numpy as np
from PIL import Image
import cv2
import vpi

# Load input into a vpi.Image
input = vpi.asimage(np.asarray('test.png')))

# Using the chosen backend,
with vpi.Backend.CUDA:
    # First convert input to NV12_ER.
    # We're overriding the default backend with CUDA.
    temp = input.convert(vpi.Format.NV12_ER, backend=vpi.Backend.CUDA)

    # Rescale the image using the chosen backend
    temp = temp.rescale((input.width//2, input.height//3))

    # Convert result back to input's format
    output = temp.convert(input.format, backend=vpi.Backend.CUDA)

# Display image
cv2.imshow("output", output.cpu())


VPI doesn’t support display.
But you can try to use it with jetson_utils.


@AastaLLL, in this example also the they’re downloading the image from GPU to CPU (output.cpu())

import numpy as np
import jetson.utils
import vpi

display = jetson.utils.glDisplay()

camera = jetson.utils.gstCamera(1920, 1280, '0')

while display.IsOpen():
    frame, width, height = camera.CaptureRGBA(zeroCopy=1)
    input = vpi.asimage(np.uint8(jetson.utils.cudaToNumpy(frame)))
    with vpi.Backend.CUDA:
        output = input.convert(vpi.Format.U8) 
        output = output.box_filter(11, border=vpi.Border.ZERO).convert(vpi.Format.RGB8)

    display.RenderOnce(jetson.utils.cudaFromNumpy(output.cpu()), width, height)
    display.SetTitle("{:s} | {:d}x{:d} | {:.1f} FPS".format("Camera Viewer", width, height, display.GetFPS()))


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.