Accessing nvds_buf_surface

Is this the proper way to make an OpenCV mat from a buffer, e.g. within a probe handing?

surface = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
frame = np.array(surface, copy=True, order='C')
frame = cv2.cvtColor(frame, cv2.COLOR_RGBA2BGRA) 

Disregard please. Found this sample

Hmm. That crashes here:

My pipeline (parameters removed for clarity):

                nvstreammux ! 
                nvinfer  ! 
                nvtracker !
                nvvideoconvert !
                video/x-raw(memory:NVMM), format=RGBA !
                nvdsosd ! 
                nvvideoconvert !
                nvv4l2h264enc ! 
                rtspclientsink 
               
                uridecodebin  ! 
                mux.sink_0                       

The probe is placed at the output sink pad of nvdosd. In the callback I’m running this once for 30 frames (taken from the sample):

    n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
    # convert python array into numpy array format in the copy mode.
    frame_copy = np.array(n_frame, copy=True, order='C')
    cv2.imwrite('./test.jpg', frame_copy)

The only line, which doesn’t crash the entire script with segmentation fault is the first

 n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)

The next line crashes.

frame_copy = np.array(n_frame, copy=True, order='C')

What can I do to narrow down the problem?

The nice thing about this is: With this segfault in the Python script I am now at the same point where I stopped in my Golang script, because I could not avoid the segfault when accessing the surface…

Oh, turns out the addition of nvbuf-memory-type=3 to nvstreammux and the two nvvideoconverts was helpful :)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.