title: Sliding window over an image OpenCV
body: <p>I am trying to define a window that scans across an image, I want to  find the average RGB values in each window and output them.</p>
  
  <p>I have managed to get the average RGB values for the entire image like this:</p>
  
  <pre><code>img = cv2.imread('images/0021.jpg')
  
  mean = cv2.mean(img)
  
  print mean[0]
  print mean[1]
  print mean[2]
  </code></pre>
  
  <p>Gives:</p>
  
  <pre><code>#Output
  51.0028081597
  63.1069849537
  123.663025174
  </code></pre>
  
  <p>How could I apply this mean function to a moving window and output the values for each window?</p>
  
  <p>EDIT:</p>
  
  <p>Here is what I have now:</p>
  
  <pre><code>img = cv2.imread('images/0021.jpg')
  
  def new(img):
      rows,cols = img.shape
      final = np.zeros((rows, cols, 3, 3))
      for x in (0,1,2):
          for y in (0,1,2):
              img1 = np.vstack((img[x:],img[:x]))
              img1 = np.column_stack((img1[:,y:],img1[:,:y]))
              final[x::3,y::3] = np.swapaxes(img1.reshape(rows/3,3,cols/3,-1),1,2)
              b,g,r = cv2.split(final)
              rgb_img = cv2.merge([r,g,b])
              mean = cv2.mean(rgb_img)
              print mean[0]
              print mean[1]
              print mean[2]
  </code></pre>
  
  <p>But now I am getting zero output. </p>