title: Fastest way to detect the non/least-changing pixels of successive images
body: <p>I want to find the pixels of a video stream that are static. This way I can detect logos and other non-moving items on my video stream. My idea behind the script is as follows:</p>
  
  <ul>
  <li>collect a number of equally-sized and graysized frames in a list called <code>previous</code></li>
  <li>if a certain amount of frames is collected, call the function <code>np.std</code></li>
  <li>This function loops over all the <code>x-</code>and <code>y-coordinates</code> of a new image.</li>
  <li>Calculate the standard deviation of the grayvalues for all the coordinates based on the grayvalues of the corresponding coordinates of all the frames</li>
  </ul>
  
  <p>My script:</p>
  
  <pre><code>import math
  import cv2
  import numpy as np
  
  
  video = cv2.VideoCapture(0)
  previous = []
  n_of_frames = 200
  
  while True:
     ret, frame = video.read()
     if ret:
        cropped_img = frame[0:150, 0:500]
        gray = cv2.cvtColor(cropped_img, cv2.COLOR_BGR2GRAY)
        if len(previous) == n_of_frames:
           stdev_gray = np.std(previous, axis=2)
           previous = previous[1:]
           previous.append(gray)
        else:
           previous.append(gray)
  
        cv2.imshow('frame', frame)
  
        key = cv2.waitKey(1)
        if key == ord('q'):
           break
  
  video.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>This process is pretty slow and I am curious if there are faster ways to do this. I am open to Cython etc. Many many thanks in advance!</p>