title: OpenCV VideoCapture and (-215:Assertion failed) !_src.empty() in function 'cvtColor'
body: <p>This code originally worked fine.
  But when I run it again, the following error appears.
  I searched a lot about the error, but couldn't find a solution.
  Any help would be appreciated.</p>
  <pre><code>cv2.error: OpenCV(4.4.0) /tmp/pip-wheel-frffvd08/opencv-python/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
  </code></pre>
  <p>The code below is the Python code I wrote.</p>
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture(0)
  cap.set(3,640) # set Width
  cap.set(4,480) # set Height
  
  while(True):
  #while(cap.isOpened()):
      ret, frame = cap.read()
      frame = cv2.flip(frame, -1) # Flip camera vertically
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
      cv2.imshow('frame', frame)
      cv2.imshow('gray', gray)
  
      k = cv2.waitKey(30) &amp; 0xff
      if k == 27: # press 'ESC' to quit
          break
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>