How do I draw a box using jetson-utils:cudaOverlay() in Python?

Jetson Xavior NX, Python, jetson-utils

How do I draw a square box using cudaOverlay(). I am using python and can’t figure out how this is done. I searched the forum and didn’t find any example to do this. I read that it can be done but no clear example Python code was given.

I have a the topleft,toprignt,bottomright,bottomleft points and need to draw a rectangle with the x dimensions plus I don’t want the area to be filled in. just the outside with lines that are about 1 to 2 pixels thick.

I have a cudaimage that I want to draw these lines on. I am currently doing it in opencv, but I don’t want to convert to numpy and back , as this seems to be less efficient.

Another issue is I need to convert my color space. RGB>BGR and BGR>RGB. Can i do that using jetson-utils? I also am doing that in opencv but that is slow and I want to use the gpu to do that as well.


The cudaOverlay() function is for composting two images and not drawing rectangles. If you are using detectNet, that can overlay boxes (but they are filled, not outline). Long ago I had tried an outline-based method but it was buggy.

Yes, you can do that using the cudaConvertColor() function. For example, this will convert from RGB->BGR:

imgInput = jetson.utils.loadImage('my_image.jpg', format='rgb8')
imgOutput = jetson.utils.cudaAllocMapped(width=imgInput.width, height=imgInput.height, format='bgr8')
jetson.utils.cudaConvertColor(imgInput, imgOutput)

I am using detectNet for box creation, however the boxes I want to draw are not related to detectNet’s boxes. They are for some other purpose. ie Detection zones where I want to only focus on. This is for display purposes for user to see where the detection zones are only being used. I guess What I really am looking for is a Cuda enabled library for drawing and text overlay like what OpenCV has. I would use OpenCV drawcalls if I could get the GPU performance from it. Is there a Cuda enabled library I can install that would give me drawing functions like OpenCV has? I need to use Python.

How would I convert BRG-> RGB? I need to go both ways. I can use OpenCV but I want better performance.

Thanks, Mike

You would just pass in a BGR image as input and RGB image as output to cudaConverColor(), like so:

imgInput = jetson.utils.cudaAllocMapped(width=imgInput.width, height=imgInput.height, format='bgr8')
imgOutput = jetson.utils.cudaAllocMapped(width=imgInput.width, height=imgInput.height, format='rgb8')
jetson.utils.cudaConvertColor(imgInput, imgOutput)