Dsexample code

613     CUgraphicsResource *cu;                                                                                                                                                                                                                          
614     cuGraphicsEGLRegisterImage(cu, dsexample->inter_buf->surfaceList[0].mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);//crash!!
617     /* Use interop APIs cuGraphicsEGLRegisterImage and                           
618      * cuGraphicsResourceGetMappedEglFrame to access the buffer in CUDA */       
620     /* Destroy the EGLImage */       

Above is gstdsexample.cpp of deepstream 5.0 gst-plugin example code. I just added those two lines as suggested by the comments below and included a header.
It crashes at 614 line.
How can I get a opencv matrix from gstdsexample.cpp code example?

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson Nano )
• DeepStream Version .5.0
• JetPack Version (valid for Jetson only 4.4.1)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Can you refer to the document first? https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_sample_custom_gstream.html#accessing-nvbufsurface-memory-in-opencv

I did. That document does not give enough info. I have a jetson.

Sorry for late response, the following code can work:

CUgraphicsResource cu;
cuGraphicsEGLRegisterImage(&cu, dsexample->inter_buf->surfaceList[0].mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
cuGraphicsUnregisterResource (cu);

You can not use a null resource pointer with cuGraphicsEGLRegisterImage().