How Can get FPS in apps python in deepstream

Jetson Nano
Jetpack 4.5
Deepstream 5.1

I have a single source single stream setup.
I tried using this solution for single stream but the FPS result is returned as None

Please read the code in apps/common/FPS.py. get_fps() is not to get FPS value so there is no result. You can not print the result. It is open source, please use it as the code itself.

Oh I understand my mistake, So just calling function should do make it work.

But in just calling the function like this

        fps_stream=GETFPS(0)    
        fps_stream.get_fps()

Yields the same result as "None"

Am I still missing something ?

Can you upload the whole code but not pieces? Where did you get “None”.

You must run fps_stream.get_fps() in a loop thread. Please read the code.

The code

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

        frame_number=frame_meta.frame_num
        num_rects = frame_meta.num_obj_meta
        l_obj=frame_meta.obj_meta_list
        while l_obj is not None:
            try:
                # Casting l_obj.data to pyds.NvDsObjectMeta
                #obj_meta=pyds.glist_get_nvds_object_meta(l_obj.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.0)
            rect_params = obj_meta.rect_params
            #print("Name = {} ,Top = {}, Left = {}, Height = {}, Width = {}".format(pgie_classes_str[obj_meta.class_id],int(rect_params.top),int(rect_params.left),int(rect_params.height),int(rect_params.width)))
            print("Class_ID =",obj_meta.class_id)
            try: 
                l_obj=l_obj.next
            except StopIteration:
                break

        # 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.
        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]
        # Setting display text to be shown on screen
        # Note that the pyds module allocates a buffer for the string, and the
        # memory will not be claimed by the garbage collector.
        # Reading the display_text field here will return the C address of the
        # allocated string. Use pyds.get_string() to get the string content.

        fps_stream=GETFPS(1)    
        fps_stream.get_fps()
        

        # Now set the offsets where the string should appear
        py_nvosd_text_params.x_offset = 10
        py_nvosd_text_params.y_offset = 12

        # Font , font-color and font-size
        py_nvosd_text_params.font_params.font_name = "Serif"
        py_nvosd_text_params.font_params.font_size = 10
        # 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, 0.0, 0.0, 1.0)
        # Using pyds.get_string() to get display_text as string
        print(pyds.get_string(py_nvosd_text_params.display_text))
        pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)
        try:
            l_frame=l_frame.next
        except StopIteration:
            break

Also I have used the imports

import sys
sys.path.append('../')
import gi
import time
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
from common.is_aarch_64 import is_aarch64
from common.bus_call import bus_call
from common.FPS import GETFPS
import pyds

You can not use “fps_stream=GETFPS(1)” in the loop thread. Please place it in main thread. I think we already have such sample in deepstream-test3

1 Like