Why custom label is not displayed?

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) RTX4080
• DeepStream Version 7.0
Trying to display custom label on display.
I have added the following lines of codes in the tiler_sink_pad_buffer_probe.
I like to display label msg_meta.objClassId = 14. According to label file, classID 14 is stand. But sand is not displayed.
The whole code is as follows.

def tiler_sink_pad_buffer_probe(pad, info, u_data):
    global CameraWidgets
    frame_number = 0
    num_rects = 0
    gst_buffer = info.get_buffer()
    if not gst_buffer:
        print("Unable to get GstBuffer ")
        return

    # Retrieve batch metadata from the gst_buffer
    # Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
    # C address of gst_buffer as input, which is obtained with hash(gst_buffer)
    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))

    l_frame = batch_meta.frame_meta_list
    while l_frame is not None:
        try:            
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
        except StopIteration:
            break
        
        frame_number = frame_meta.frame_num
        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')
        # convert the array into cv2 default color format
        frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGR)
        CameraWidgets[frame_meta.pad_index].set_frame(frame_copy)
        if platform_info.is_integrated_gpu(): # If Jetson, since the buffer is mapped to CPU for retrieval, it must also be unmapped
            pyds.unmap_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id) # The unmap call should be made after operations with the original array are complete.
                                                                               #  The original array cannot be accessed after this call.
        l_obj = frame_meta.obj_meta_list
        while l_obj is not None:
                try:
                    obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
                except StopIteration:
                    continue
                user_event_meta = pyds.nvds_acquire_user_meta_from_pool(batch_meta)
                if user_event_meta:
                    msg_meta = pyds.alloc_nvds_event_msg_meta(user_event_meta)
                    msg_meta.bbox.top = obj_meta.rect_params.top-20
                    msg_meta.bbox.left = obj_meta.rect_params.left
                    msg_meta.bbox.width = obj_meta.rect_params.width
                    msg_meta.bbox.height = obj_meta.rect_params.height
                    msg_meta.objClassId = 14
                    user_event_meta.user_meta_data = msg_meta
                    user_event_meta.base_meta.meta_type = pyds.NvDsMetaType.NVDS_EVENT_MSG_META
                    pyds.nvds_add_user_meta_to_frame(frame_meta, user_event_meta)
                        
                    
                try:
                    l_obj = l_obj.next
                except StopIteration:
                    break
                 
        global perf_data
        stream_index = "stream{0}".format(frame_meta.pad_index)
        perf_data.update_fps(stream_index)
        
        try:
            l_frame = l_frame.next
        except StopIteration:
            break

    return Gst.PadProbeReturn.OK

Label file is attached.
labels_peoplenet.txt (993 Bytes)

Config file also have change at
dstest_imagedata_config.txt (2.0 KB)

You can refer to our source code deepstream_test_1.py. If you want to customize what display on the screen, you need to use the display_meta.

Is it possible to turn off pgie label display and just display custom display, can?
For custom display, I can follow deepstream_test_1.py.
If i set flag display-text to 0, all both (pgie and custom) won’t be displayed, right?
How can I turn off pgie label and show custom label only?

I have modified code as follows. But display not come out yet.

display_meta=pyds.nvds_acquire_display_meta_from_pool(batch_meta)
py_nvosd_text_params = display_meta.text_params[0]
py_nvosd_text_params.display_text = 'test'#d_ret[b_i]['labels'][0]
# Now set the offsets where the string should appear
py_nvosd_text_params.x_offset = 10#int(obj_meta.rect_params.left)
py_nvosd_text_params.y_offset = 20#int(obj_meta.rect_params.top-50)
# Font , font-color and font-size
py_nvosd_text_params.font_params.font_name = "Serif"
py_nvosd_text_params.font_params.font_size = 20
# set(red, green, blue, alpha); set to White
py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)
# Text background color
py_nvosd_text_params.set_bg_clr = 1
 # set(red, green, blue, alpha); set to Black
py_nvosd_text_params.text_bg_clr.set(0.0, 1.0, 0.0, 1.0)
pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)

The whole code is as follows.

def tiler_sink_pad_buffer_probe(pad, info, u_data):
    global CameraWidgets
    frame_number = 0
    num_rects = 0
    gst_buffer = info.get_buffer()
    if not gst_buffer:
        print("Unable to get GstBuffer ")
        return

    # Retrieve batch metadata from the gst_buffer
    # Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
    # C address of gst_buffer as input, which is obtained with hash(gst_buffer)
    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))

    l_frame = batch_meta.frame_meta_list
    while l_frame is not None:
        try:
            # Note that l_frame.data needs a cast to pyds.NvDsFrameMeta
            # The casting is done by pyds.NvDsFrameMeta.cast()
            # The casting also keeps ownership of the underlying memory
            # in the C code, so the Python garbage collector will leave
            # it alone.
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
        except StopIteration:
            break
        
        frame_number = frame_meta.frame_num
        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')
        # convert the array into cv2 default color format
        frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGR)
        CameraWidgets[frame_meta.pad_index].set_frame(frame_copy)
        time.sleep(0.002)
        if platform_info.is_integrated_gpu(): # If Jetson, since the buffer is mapped to CPU for retrieval, it must also be unmapped
            pyds.unmap_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id) # The unmap call should be made after operations with the original array are complete.
                                                                               #  The original array cannot be accessed after this call.

        d_ret = objects_metainfo.retrieve(frame_meta.pad_index)
        if len(d_ret) > 0:
            #print("camera idx " + str(frame_meta.pad_index))
            #print(d_ret)
            l_obj = frame_meta.obj_meta_list
            while l_obj is not None:
                try:
                    obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
                except StopIteration:
                    continue
                for b_i in range(len(d_ret)):
                    #print(d_ret[b_i]['labels'])
                    boxA = [d_ret[b_i]['box'][0][0], d_ret[b_i]['box'][0][1], d_ret[b_i]['box'][1][0], d_ret[b_i]['box'][1][1]] 
                    boxB = [obj_meta.rect_params.left, obj_meta.rect_params.top, obj_meta.rect_params.left+obj_meta.rect_params.width, obj_meta.rect_params.top+obj_meta.rect_params.height]
                    xA = max(boxA[0], boxB[0])
                    yA = max(boxA[1], boxB[1])
                    xB = min(boxA[2], boxB[2])
                    yB = min(boxA[3], boxB[3])
                    # compute the area of intersection rectangle
                    interArea = abs(max((xB - xA, 0)) * max((yB - yA), 0))
                    if interArea == 0:
                        return 0
                    # compute the area of both the prediction and ground-truth
                    # rectangles
                    boxAArea = abs((boxA[2] - boxA[0]) * (boxA[3] - boxA[1]))
                    boxBArea = abs((boxB[2] - boxB[0]) * (boxB[3] - boxB[1]))
                    # compute the intersection over union by taking the intersection
                    # area and dividing it by the sum of prediction + ground-truth
                    # areas - the interesection area
                    iou = interArea / float(boxAArea + boxBArea - interArea)
                    if iou > 0.0:                        
                        display_meta=pyds.nvds_acquire_display_meta_from_pool(batch_meta)
                        py_nvosd_text_params = display_meta.text_params[0]
                        py_nvosd_text_params.display_text = 'test'#d_ret[b_i]['labels'][0]
                        # Now set the offsets where the string should appear
                        py_nvosd_text_params.x_offset = 10#int(obj_meta.rect_params.left)
                        py_nvosd_text_params.y_offset = 20#int(obj_meta.rect_params.top-50)
                        # Font , font-color and font-size
                        py_nvosd_text_params.font_params.font_name = "Serif"
                        py_nvosd_text_params.font_params.font_size = 20
                        # set(red, green, blue, alpha); set to White
                        py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)
                        # Text background color
                        py_nvosd_text_params.set_bg_clr = 1
                        # set(red, green, blue, alpha); set to Black
                        py_nvosd_text_params.text_bg_clr.set(0.0, 1.0, 0.0, 1.0)
                        pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)
                        
                           
                        
                    #print(boxA)
                    #print(boxB) 
                    #print(iou)
                try:
                    l_obj = l_obj.next
                except StopIteration:
                    break
                 
        global perf_data
        stream_index = "stream{0}".format(frame_meta.pad_index)
        perf_data.update_fps(stream_index)
        
        try:
            l_frame = l_frame.next
        except StopIteration:
            break

    return Gst.PadProbeReturn.OK

Yes.

You can try deleting the contents of your label config file.

The following code supposed to display text at fixed position in display. But it didn’t.

def tiler_sink_pad_buffer_probe(pad, info, u_data):
    global CameraWidgets
    frame_number = 0
    num_rects = 0
    gst_buffer = info.get_buffer()
    if not gst_buffer:
        print("Unable to get GstBuffer ")
        return

    
    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))

    l_frame = batch_meta.frame_meta_list
    while l_frame is not None:
        try:
            # Note that l_frame.data needs a cast to pyds.NvDsFrameMeta
            # The casting is done by pyds.NvDsFrameMeta.cast()
            # The casting also keeps ownership of the underlying memory
            # in the C code, so the Python garbage collector will leave
            # it alone.
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
        except StopIteration:
            break      
        
        l_obj = frame_meta.obj_meta_list
        while l_obj is not None:
                try:
                    obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
                except StopIteration:
                    continue
                
                display_meta=pyds.nvds_acquire_display_meta_from_pool(batch_meta)
                display_meta.num_labels = 1
                py_nvosd_text_params = display_meta.text_params[0]
                py_nvosd_text_params.display_text = 'test'#d_ret[b_i]['labels'][0]
                # Now set the offsets where the string should appear
                py_nvosd_text_params.x_offset = 10
                py_nvosd_text_params.y_offset = 20
                # Font , font-color and font-size
                py_nvosd_text_params.font_params.font_name = "Serif"
                py_nvosd_text_params.font_params.font_size = 20
                # set(red, green, blue, alpha); set to White
                py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)
                # Text background color
                py_nvosd_text_params.set_bg_clr = 1
                # set(red, green, blue, alpha); set to Black
                py_nvosd_text_params.text_bg_clr.set(0.0, 1.0, 0.0, 1.0)
                pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)

                try:
                    l_obj = l_obj.next
                except StopIteration:
                    break
                 
        global perf_data
        stream_index = "stream{0}".format(frame_meta.pad_index)
        perf_data.update_fps(stream_index)
        
        try:
            l_frame = l_frame.next
        except StopIteration:
            break

    return Gst.PadProbeReturn.OK

I am going to display on every object inside the frame with custom display. Is display_meta the right meta to use?

Yes. Could you attach your whole piepline and the position where the probe function you added?

I found problem in my code. Thanks

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