Deepstream-rtsp-in-rtsp-out : Count the number of people return zero

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) nano
• DeepStream Version 7.0
• JetPack Version (valid for Jetson only) 6.0
• TensorRT Version 8.6.2.3-1+cuda12.2
• NVIDIA GPU Driver Version (valid for GPU only) NVIDIA-SMI 540.2.0
• Issue Type( questions, new requirements, bugs)

Actually, modifying the def pgie_src_pad_buffer_probe with count logic: even after that it return zero.

Frame Number=1432 Number of Objects=20 Person_count=0
Frame Number=1433 Number of Objects=21 Person_count=0
Frame Number=1434 Number of Objects=21 Person_count=0
Frame Number=1435 Number of Objects=19 Person_count=0
Frame Number=1436 Number of Objects=22 Person_count=0
Frame Number=1437 Number of Objects=18 Person_count=0
Frame Number=1438 Number of Objects=20 Person_count=0
Frame Number=1439 Number of Objects=18 Person_count=0
Frame Number=1440 Number of Objects=20 Person_count=0
nvstreammux: Successfully handled EOS for source_id=0
Frame Number=1441 Number of Objects=0 Person_count=0

Code modified :

def pgie_src_pad_buffer_probe(pad, info, u_data):
frame_number = 0
num_rects = 0
obj_counter = {
PGIE_CLASS_ID_PERSON: 0, # Initialize person count to 0
}

gst_buffer = info.get_buffer()
if not gst_buffer:
    print("Unable to get GstBuffer ")
    return

# Retrieve batch metadata from the 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
    num_rects = frame_meta.num_obj_meta  # Number of objects in the frame

    # Access the object metadata list
    l_obj = frame_meta.obj_meta_list
    while l_obj is not None:
        try:
            obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
        except StopIteration:
            break

        # Increment the counter for detected person objects
        if obj_meta.class_id == PGIE_CLASS_ID_PERSON:
            obj_counter[PGIE_CLASS_ID_PERSON] += 1

        # Set the border color of the object to blue
        obj_meta.rect_params.border_color.set(0.0, 0.0, 1.0, 0.8)

        try:
            l_obj = l_obj.next
        except StopIteration:
            break

    # Display person count and other metadata
    display_text = f"Frame Number={frame_number} Number of Objects={num_rects} Person_count={obj_counter[PGIE_CLASS_ID_PERSON]}"
    print(display_text)  # Optional: Print to console for debugging

    # Add text display to the frame (example, using pyds.NvOSD_TextParams)
    py_nvosd_text_params = pyds.NvOSD_TextParams()
    py_nvosd_text_params.display_text = display_text
    py_nvosd_text_params.x_offset = 10
    py_nvosd_text_params.y_offset = 12
    py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)
    py_nvosd_text_params.font_params.font_size = 10
    py_nvosd_text_params.font_params.font_name = "Serif"
    py_nvosd_text_params.set_bg_clr = 1
    py_nvosd_text_params.text_bg_clr.set(0.0, 0.0, 0.0, 0.5)

    # (Optional) Display RTSP timestamp if available
    if ts_from_rtsp:
        ts = frame_meta.ntp_timestamp / 1000000000
        print("RTSP Timestamp:", datetime.datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))

    try:
        l_frame = l_frame.next
    except StopIteration:
        break

return Gst.PadProbeReturn.OK

Refer to this patch.

diff --git a/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py b/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
index 51379aa..f62b8ef 100755
--- a/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
+++ b/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
@@ -52,6 +52,7 @@ pgie_classes_str = ["Vehicle", "TwoWheeler", "Person", "RoadSign"]
 # pgie_src_pad_buffer_probe  will extract metadata received on OSD sink pad
 # and update params for drawing rectangle, object information etc.

+PGIE_CLASS_ID_PERSON = 2

 def pgie_src_pad_buffer_probe(pad, info, u_data):
     frame_number = 0
@@ -77,6 +78,34 @@ def pgie_src_pad_buffer_probe(pad, info, u_data):
         except StopIteration:
             break

+        # Access the object metadata list
+        l_obj = frame_meta.obj_meta_list
+        num_rects = frame_meta.num_obj_meta
+        obj_counter = {
+            PGIE_CLASS_ID_PERSON: 0, # Initialize person count to 0
+        }
+        while l_obj is not None:
+            try:
+                obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
+            except StopIteration:
+                break
+
+            # Increment the counter for detected person objects
+            if obj_meta.class_id == PGIE_CLASS_ID_PERSON:
+                obj_counter[PGIE_CLASS_ID_PERSON] += 1
+
+            # Set the border color of the object to blue
+            obj_meta.rect_params.border_color.set(0.0, 0.0, 1.0, 0.8)
+
+            try:
+                l_obj = l_obj.next
+            except StopIteration:
+                break
+
+        # Display person count and other metadata
+        display_text = f"Frame Number={frame_number} Number of Objects={num_rects} Person_count={obj_counter[PGIE_CLASS_ID_PERSON]}"
+        print(display_text)  # Optional: Print to console for debugging
+
         frame_number = frame_meta.frame_num
         print(
             "Frame Number=",