title: openCV Error in cvtColor function: Assertion failed (scn == 3 || scn == 4)
body: <p>I want to simply load a video file, convert it to grayscale and the display it. Here is my code: </p>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture('cars.mp4')
  
  while(cap.isOpened()):
      # Capture frame-by-frame
      ret, frame = cap.read()
      #print frame.shape   
  
  
      # Our operations on the frame come here
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
      # Display the resulting frame
      cv2.imshow('frame',gray)
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  
  
  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>The video plays in grayscale till the end. Then it freezes and the window becomes Not Responding and I get the following error in the terminal:</p>
  
  <pre><code>OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/clive/Downloads/OpenCV/opencv-2.4.9/modules/imgproc/src/color.cpp, line 3737
  Traceback (most recent call last):
    File "cap.py", line 13, in &lt;module&gt;
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  cv2.error: /home/clive/Downloads/OpenCV/opencv-2.4.9/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cvtColor
  </code></pre>
  
  <p>I uncommented the statement print frame.shape. It keeps printing 720,1028,3. But after the video plays till the end, freezes and after a while it closes and it returns     </p>
  
  <pre><code>print frame.shape   
  AttributeError: 'NoneType' object has no attribute 'shape'
  </code></pre>
  
  <p>I understand that this assertion failure massage usually means that I'm trying to convert an empty image. I added a check for empty image before starting to process it using the if(ret): statement. (Any other way of doing it??)</p>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture('cars.mp4')
  
  while(cap.isOpened()):
      # Capture frame-by-frame
      ret, frame = cap.read()
      #print frame.shape   
  
      if(ret): #if cam read is successfull
          # Our operations on the frame come here
          gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
          # Display the resulting frame
          cv2.imshow('frame',gray)
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break
      else:
          break
  
  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>This time the video plays till the end and the window still freezes and closes after a few seconds. This time I don't get any error. But why does the window freeze? How can I fix that?</p>