How to convert dwImageGL to dwImageCUDA or dwImageHandle_t

Hi,

I am reading a .png file via the dwRenderEngine_createImageGLFromFile function that returns a dwImageGL. Since I would like to pass this frame into one of the DNN’s (say landmarkPerception), I believe I need to convert it to dwImageCUDA.

When I manually create a CPUimage as dwImageCPU, I can do this by converting via the m_streamerCPU2CUDA and then converting the CUDA handle to the struct.

So basially I am looking for a conversion from dwImageGL to any of the CPU or CUDA handles and structs (dwImageCUDA,dwImageCPU, dwImageHandle_t)

Dear goksan.isil,
You still need to use ImageStreamer(GL-> CUDA) where producer is GL and consumer is CUDA.
Please check ImageStreamer samples on how to do this. Also, please read ImageStreamer documentation in /usr/local/driveworks-2.0/doc/nvsdk_html/image_mainsection.html to know more details

Hi SivaRamaKrishna,

Thanks for the quick reply.

I have tried the ImageStreamer(GL-> CUDA) but got the error DW_NOT_AVAILABLE: The requested streamer type is not available error.

I can see from the documentation that Gl to CUDA conversions for RGBA, UINT8 are available, so not sure about the problem. Below is the relevant part of my code.

// streamer from GL to CUDA
dwImageStreamerHandle_t m_streamerGL2CUDA = DW_NULL_HANDLE;



dwImageProperties glProp{};
glProp.type = DW_IMAGE_GL;
glProp.width = 1913;
glProp.height = 1189;
glProp.format = DW_IMAGE_FORMAT_RGBA_UINT8;
glProp.memoryLayout = DW_IMAGE_MEMORY_TYPE_DEFAULT;

        // get sample image
        dwRenderEngine_createImageGLFromFile(&m_sampleImage,(DataPath::get() + "/samples/renderer/cars.png").c_str(),m_renderEngine);

        status = dwImageStreamer_initialize(&m_streamerGL2CUDA, &glProp, DW_IMAGE_CUDA, m_sdk);
        if (status != DW_SUCCESS) {
            logError("Cannot init image streamer m_streamerGL2CUDA: %s\n", 
            dwGetStatusName(status));
            return false;
        }

Dear goksan.isil,
It seems GL → CUDA is not possible using ImageStreamer. Let me confirm with internal team and update you.

Hi,

I have found an alternative streamer function called dwImageStreamerGL_initialize that can handle GL->CUDA.

It would be good if you can confirm this though:)

Yes. dwImageStreamer_initialize supports only CPU, CUDA, NVMEDIA as producers. You need to use dwImageStreamerGL_initialize() function if GL is producer.

Thank you.

As the last step, since the dwRenderEngine_createImageGLFromFile function returns dwImageGL, I need to convert this into a dwImageHandle_t to be able to pass it into m_streamerGL2CUDA.

Haven’t managed to find such a conversion yet. Basically I’m looking for the equivalent of dwImage_getCPU function for GL.

Is there such a function?

ok, I have found it I guess:

dwImage_getGL

I have one final error, along the following lines during runtime:

    dwImageGL* imageGL;
    CHECK_DW_ERROR(dwImage_getGL(&imageGL, m_imageGL));
    CHECK_DW_ERROR(dwImageStreamer_producerSend(m_imageGL, m_streamerGL2CUDA));

“DW Error DW_INVALID_ARGUMENT executing DW function:
dwImageStreamer_producerSend(m_imageGL, m_streamerGL2CUDA)”


I have checked that the streamer GL-> CUDA is initialized correctly.

I have no content in imageGL on purpose to make sure that the fields are not causing the problem.

Dear goksan,
Note that, when GL is producer or consumer, you need to use different APIs. Please check with dwImageStreamerGL_producerSend(). Also, take a look at /usr/local/driveworks-2.0/doc/nvsdk_html/isualization_2interop_2ImageStreamer_8h.html

Awesome! Now everything works!

Thanks a lot for the support SivaRamaKrishna :)

For future users, would it make sense to make it illegal to pass DW_IMAGE_CUDA type as destination and DW_IMAGE_GL type as source to dwImageStreamerGL_initialize ?