How to add OSD to frame which data in GPU ?

Hi,

I want to add a logo in video stream. And I use EGL to get every frame, the frame data in GPU. Does there has any interface or library to do this quickly ?

Thanks.

Other users may share 3rdparty applications for this.

You can also refer to tegra_multimedia_api\samples\common\algorithm\cuda and implement it via CUDA.

Hi, DaneLLL

I have found /tegra_multimedia_api/include/nvosd.h . And now I want to put the text to image. But it’s param make me confuse: 1. If I need fill every param ? The NvOSD_FontParams font_name, dose it mean font type ? I can fill with what , the font size range from 0 to 100 ? there is not specific illustratation. If any demo show it? 2. the NvOSD_Mode support MODE_CPU and MODE_HW, and the CPU only support RGBA data, the DMAbuf seems not support RGBA.

Hi,

And now I have an eglImage in GPU with RGBA . How can I acquire fd ?

AFAIK, if you don’t bind a Nvbuffer with eglImage first, you cannot get the fd from eglImage.

You need to create a NvBuffer and then use “NvEGLImageFromFd” to get the eglImage.

Also, MODE_HW does not support text osd.

1 Like

As WayneWWW says, please follow
[url]https://devtalk.nvidia.com/default/topic/1032065/jetson-tx1/cueglstreamconsumer-nv12-gt-gstreamer-appsrc/post/5251453/#5251453[/url]

Hi,

I have just checked the NvBufferCreate , and I found the color format seems not support RGBA.

typedef enum
{
  NvBufferColorFormat_YUV420,
  NvBufferColorFormat_YVU420,
  NvBufferColorFormat_NV12,
  NvBufferColorFormat_NV21,
  NvBufferColorFormat_UYVY,
  NvBufferColorFormat_VYUY,
  NvBufferColorFormat_YUYV,
  NvBufferColorFormat_YVYU,
  NvBufferColorFormat_ABGR32,
  NvBufferColorFormat_XRGB32,
  NvBufferColorFormat_ARGB32,
  NvBufferColorFormat_Invalid,
} NvBufferColorFormat;

should I convert RGBA to ABGR32 ?

Hi ClancyLian,
NvBufferColorFormat_ABGR32 is 32 bit in [8-bit R:8-bit G:8-bit B:8-bit A]. If your data is not in this order, you need to do format conversion.

Hi, DaneLLL
I have use this to get fd from EGLimage:

if (-1 == NvBufferCreate(&fdOSD, cameraWidth, cameraHeight, NvBufferLayout_Pitch, 
              NvBufferColorFormat_ABGR32)) {
        printf("Create nvbuffer failed.\n");
        throw;
    }
    display = EGLDisplayAccessor::getInstance();
    eglImageOSD = NvEGLImageFromFd(display, fdOSD);
    CUgraphicsResource resourceOSD;
    CUresult statusOSD;
    cudaFree(0);
    statusOSD = cuGraphicsEGLRegisterImage(&resourceOSD, eglImageOSD, CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD);
    if (statusOSD != CUDA_SUCCESS) {
        printf("cuGraphicsEGLRegisterImage failed: %d.\n", statusOSD);
        throw;
    }

    statusOSD = cuGraphicsResourceGetMappedEglFrame(&frameOSD, resourceOSD, 0, 0);
    if (statusOSD != CUDA_SUCCESS) {
        printf("cuGraphicsResourceGetMappedEglFrame failed: %d.\n", statusOSD);
        throw;
    }

    context = nvosd_create_context();

And then:

frameOSD.frame.pPitch[0] = imgData; //imgData is the image data in GPU with format RGBA

    NvOSD_TextParams textParam;
    textParam.display_text = "HELLO";
    textParam.x_offset = 100;
    textParam.y_offset = 100;
    textParam.font_params.font_name = "Arial";
    textParam.font_params.font_size = 40;
    textParam.font_params.font_color.red = 1.0;
    textParam.font_params.font_color.green = 1.0;
    textParam.font_params.font_color.blue = 1.0;
    textParam.font_params.font_color.alpha = 0.5;

    int ret = nvosd_put_text(context, MODE_CPU, fdOSD, 1, &textParam);

The ret is success, but I can’t see any text in the image after I added OSD in it.

Please follow this thread.

https://devtalk.nvidia.com/default/topic/1021210/unable-to-display-text-using-nvosd_put_text-/

Hi, WayneWWW

1.Does the OSD support Chinese font ?

2.this OSD are written to the image permanent ? Or temporary ? When I encode it. can I see it in the image?

No, it does not support Chinese font and it should directly put it on your frame so you could see it even after encoding.

@WayneWWW, would it be possible to get the source code for the NVOSD library? I want to see how it puts boxes and text on top of video frames. And I want to see if I can modify the library to draw lines or bitblip graphics.

Sorry, no source code here. If you need such resources, please contact nvidia sales.