Sorry, after some tries I think I found the answer myself.
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.glist_get_nvds_frame_meta()
# 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.glist_get_nvds_frame_meta(l_frame.data)
frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
except StopIteration:
break
l_obj = frame_meta.obj_meta_list
new_objs = []
while l_obj is not None:
try:
# Casting l_obj.data to pyds.NvDsObjectMeta
org_obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
# insert a single object.
new_obj_meta = pyds.nvds_acquire_obj_meta_from_pool(batch_meta)
# Set bbox properties. These are in input resolution.
rect_params = org_obj_meta.rect_params
# enlarge original box
delta_width = org_obj_meta.rect_params.width * width_ratio
new_left = max(0, (org_obj_meta.rect_params.left - delta_width // 2))
new_width = org_obj_meta.rect_params.width + delta_width
delta_height = org_obj_meta.rect_params.height * height_ratio
new_top = max(0, (org_obj_meta.rect_params.top - delta_height // 2))
new_height = org_obj_meta.rect_params.width + delta_height
rect_params.left = new_left
rect_params.top = new_top
rect_params.width = new_width
rect_params.height = new_height
new_obj_meta.class_id = org_obj_meta.class_id
new_obj_meta.confidence = org_obj_meta.confidence
new_objs.append(new_obj_meta)
except StopIteration:
break
try:
l_obj = l_obj.next
except StopIteration:
break
for new_obj_meta in new_objs:
pyds.nvds_add_obj_meta_to_frame(frame_meta, new_obj_meta, None)
print("added new_obj_meta")
try:
l_frame = l_frame.next
except StopIteration:
break
The important part is to write the new object outside of the reading loop.