title: Set a timer to know how long the unknown face was on the screen in face recognition using opencv in python?
body: <p>I'm learning face recognition using opencv in python and wondering If I can set a timer to know if the unknown face gets detected for more than 5 seconds than I will call some <code>function()</code>. So I used start time and end time inorder to get the difference of 5 but it's not working properly. Any clue to make this code working ?</p>
  <pre><code>def gen(camera1):
      startTime = time.time()
      while True:
          label, frame = camera1.get_frame()
          if label==&quot;unknown&quot;:
              endTime = time.time()
              if (endTime - startTime &gt; 5):
                  print(&quot;Inside If condition Longer than 5 seconds&quot;)
                  function()
          else:
              yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n'
              yield frame
              yield b'\r\n\r\n'
              yield label
  
  </code></pre>