title: How to check image against trained model while still displaying camera recording?
body: <p>I have this python program which with the help <code>OpenCV (cv2)</code> opens a camera session. I have set an area of interest where an image is being extracted from the camera recording and is being passed at a trained <code>keras</code> model as a parameter to get a prediction. My question is how could I check against the model only every 10 seconds? I tried using <code>time.sleep(10)</code>  which freezes the whole window (as it takes place inside the while loop) for 10 seconds. That means that the whole recording stops every 10 seconds, whereas I wanna be able to record constantly and check against the model only every 10 seconds.
  This is my code so far:</p>
  <pre><code>import cv2
  import numpy as np
  from tensorflow import keras
  import time
  
  #import playsound
  
  # wait for the sound to finish playing?
  blocking = True
  
  model = keras.models.load_model(&quot;model2.h5&quot;)
  cam = cv2.VideoCapture(0)
  
  ####region of interest dimensions
  startX =  800
  startY = 0
  finishX = 1200
  finishY = 400
  while(1):
      ret, frame = cam.read()
      if ret:
          ### displays video recording and region of interest
          frame = cv2.flip(frame,1)
          display = cv2.rectangle(frame.copy(),(startX,startY),(finishX,finishY),(0,0,255),2) 
          cv2.imshow('Total Input',display)
          ROI = frame[startY:finishY, startX:finishX].copy()
          cv2.imshow('Region of Interest', ROI)
           
          #pauses for 10 seconds
          time.sleep(10)
  
          img = cv2.resize(display, (128, 128)) #R
          img = img.reshape(1, 128, 128, 3)
          predictions = model.predict(img) # Make predictions towards the test set
          predicted_label = np.argmax(predictions) # Get index of the predicted label from prediction
          print(predicted_label)
          if cv2.waitKey(10) &amp; 0xFF == ord('q'):
            break
  
  cam.release()
  cv2.destroyAllWindows()
  </code></pre>
  <p>I am thinking if I should maybe use a thread but I am not really familiar with threads in python. Does anyone have an idea how this could be done?</p>