To solve this just add assert after loading the image/frame. 
For image:
image = cv2.imread('myimage.png')
assert not isinstance(image,type(None)), 'image not found'
For video:
cap = cv2.VideoCapture(0)
    while(cap.isOpened()):
        # Capture frame-by-frame
        ret, frame = cap.read()
        if ret:
I hope this helps you.