Playout video at constant frames per sec

Change-Id: Ia81412abe2b2ffb17151d490691625aa784ef4c0
diff --git a/person_detection/app.py b/person_detection/app.py
index 1386d63..83a8d3d 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -8,6 +8,9 @@
 from flask import Flask, render_template, Response
 from argparse import ArgumentParser, SUPPRESS
 
+import fpstimer
+
+
 # import camera driver
 if os.environ.get('CAMERA'):
     Camera = import_module('camera_' + os.environ['CAMERA']).Camera
@@ -29,10 +32,12 @@
 
 def gen(camera):
     """Video streaming generator function."""
+    timer = fpstimer.FPSTimer(fps)
     while True:
         frame = camera.get_frame()
         yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
+        timer.sleep()
 
 @app.route('/video_feed/<device>')
 def video_feed(device):
@@ -56,11 +61,13 @@
                       default = "gstreamer", type=str)
     args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering",
                       default=0.0, type=float)
-    args.add_argument("--idle", action='store_true', help="Idle if no clients connected")
+    args.add_argument("-fps", "--frames_per_sec", help="Frames per second",
+                      default=15, type=float)
 
     return parser
 
 
 if __name__ == '__main__':
     args = build_argparser().parse_args()
+    fps = args.frames_per_sec
     app.run(host='0.0.0.0', debug=True)