This is a simplified version of the code I’m running inside a source probe function attached to the detection plugin in the pipeline -
while l_obj is not None:
try:
obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
if obj_meta is not None:
if """some condition is true""":
pyds.nvds_remove_obj_meta_from_frame(frame_meta, obj_meta)
except StopIteration:
break
try:
l_obj = l_obj.next
except StopIteration:
break
This is throwing segmentation faults sometimes.
Does removing an obj_meta also delete the reference to l_obj due to which l_obj.next becomes non-existent?
Do I need to accumulate all the object references I have to delete and remove them together after the object loop?
Yes, you can’t iterate and delete a linked list at the same time
Here is the correct way to do it. I deleted all person categories.
diff --git a/apps/deepstream-test1/deepstream_test_1.py b/apps/deepstream-test1/deepstream_test_1.py
index 1367fb4..37ed2a2 100755
--- a/apps/deepstream-test1/deepstream_test_1.py
+++ b/apps/deepstream-test1/deepstream_test_1.py
@@ -43,6 +43,7 @@ def osd_sink_pad_buffer_probe(pad,info,u_data):
print("Unable to get GstBuffer ")
return
+ person_objs = []
# 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)
@@ -75,13 +76,19 @@ def osd_sink_pad_buffer_probe(pad,info,u_data):
obj_meta=pyds.NvDsObjectMeta.cast(l_obj.data)
except StopIteration:
break
- obj_counter[obj_meta.class_id] += 1
- obj_meta.rect_params.border_color.set(0.0, 0.0, 1.0, 0.8) #0.8 is alpha (opacity)
+ if obj_meta.class_id == PGIE_CLASS_ID_PERSON:
+ person_objs.append(obj_meta)
+ else:
+ obj_counter[obj_meta.class_id] += 1
+ obj_meta.rect_params.border_color.set(0.0, 0.0, 1.0, 0.8) #0.8 is alpha (opacity)
try:
l_obj=l_obj.next
except StopIteration:
break
+ for person in person_objs:
+ pyds.nvds_remove_obj_meta_from_frame(frame_meta, person)
+
# Acquiring a display meta object. The memory ownership remains in
# the C code so downstream plugins can still access it. Otherwise
# the garbage collector will claim it when this probe function exits.
@@ -116,7 +123,7 @@ def osd_sink_pad_buffer_probe(pad,info,u_data):
l_frame=l_frame.next
except StopIteration:
break
-
+
return Gst.PadProbeReturn.OK