title: Is there a faster way than using a for loop way to check for greyscale in python
body: <p>I am trying to write a function which determines if an image is grayscale or not, and then convert to grayscale if not, and return that image at the end.</p>
  
  <p>The for loop code below works fine, but it's very slow. Is there a faster way to check for this? I looked through CV2 documentation but couldn't find anything offhand.</p>
  
  <pre><code>import cv2
  def grey():
      img = cv2.imread('1.jpg')
      for x in range(img.shape[0]):
          for y in range(img.shape[1]):
              if img[x,y,0] == img[x,y,1] == img[x,y,2]:
                  grey = img
              else:
                  grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      return grey
  </code></pre>