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