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

**URL:** <https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260>\
**Category:** Jetson Xavier NX\
**Tags:** python\
**Created:** [November 24, 2020, 5:40am UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260 "2020-11-24T05:40:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Mike](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@\_Mike](https://forums.developer.nvidia.com/u/_Mike)\
**Post date:** [November 24, 2020, 5:40am UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260/1 "2020-11-24T05:40:51Z")

</div>

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.

–Mike

---

<div class="post-metadata">

**Author:** ![dusty\_nv](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dusty_nv/32/14043_2.png) [@dusty\_nv](https://forums.developer.nvidia.com/u/dusty_nv)\
**Post date:** [November 24, 2020, 7:42pm UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260/3 "2020-11-24T19:42:33Z")

</div>

> [@\_Mike](#):
>
> How do I draw a square box using cudaOverlay()

The [cudaOverlay()](https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-image.md#overlay) 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.

> [@\_Mike](#):
>
> 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.

Yes, you can do that using the [cudaConvertColor()](https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-image.md#color-conversion) function. For example, this will convert from RGB-\>BGR:

```python
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)

```

---

<div class="post-metadata">

**Author:** ![\_Mike](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@\_Mike](https://forums.developer.nvidia.com/u/_Mike)\
**Post date:** [November 24, 2020, 10:53pm UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260/4 "2020-11-24T22:53:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dusty\_nv](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dusty_nv/32/14043_2.png) [@dusty\_nv](https://forums.developer.nvidia.com/u/dusty_nv)\
**Post date:** [November 25, 2020, 4:39pm UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260/5 "2020-11-25T16:39:52Z")

</div>

> [@\_Mike](#):
>
> How would I convert BRG-\> RGB? I need to go both ways. I can use OpenCV but I want better performance.

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

```bash
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)

```

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 6:42pm UTC](https://forums.developer.nvidia.com/t/how-do-i-draw-a-box-using-jetson-utils-cudaoverlay-in-python/160260/7 "2021-10-18T18:42:49Z")

</div>

Closed on October 18, 2021, 6:42pm UTC


