OpenCV VideoCapture and error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Solution 1:

The error you're seeing is one that happens if None gets passed on cv2.cvtColor.

After

ret, img = cap.read()

it's a good idea to check that img is not None before proceeding. Depending on your input source, cap.read() can fail. On one my laptops, it fails at least once before starting to return valid images.