FPS.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ################################################################################
  2. # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the "Software"),
  6. # to deal in the Software without restriction, including without limitation
  7. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. # and/or sell copies of the Software, and to permit persons to whom the
  9. # Software is furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. # DEALINGS IN THE SOFTWARE.
  21. ################################################################################
  22. import time
  23. start_time=time.time()
  24. frame_count=0
  25. class GETFPS:
  26. def __init__(self,stream_id):
  27. global start_time
  28. self.start_time=start_time
  29. self.is_first=True
  30. global frame_count
  31. self.frame_count=frame_count
  32. self.stream_id=stream_id
  33. def get_fps(self):
  34. end_time=time.time()
  35. if(self.is_first):
  36. self.start_time=end_time
  37. self.is_first=False
  38. if(end_time-self.start_time>5):
  39. print("**********************FPS*****************************************")
  40. print("Fps of stream",self.stream_id,"is ", float(self.frame_count)/5.0)
  41. self.frame_count=0
  42. self.start_time=end_time
  43. else:
  44. self.frame_count=self.frame_count+1
  45. def print_data(self):
  46. print('frame_count=',self.frame_count)
  47. print('start_time=',self.start_time)