rows, cols, _ = frame.shape AttributeError: ‘NoneType’ object has no attribute ‘shape

rows, cols, _ = frame.shape AttributeError: ‘NoneType’ object has no attribute ‘shape

大家好,我想执行下面的代码a时出错,任何人都可以帮助我

while True:
    _, frame = cap.read()
    # frame = cv2.resize(frame, None, fx=0.8, fy=0.8)
    rows, cols, _ = frame.shape
    keyboard[:] = (26, 26, 26)
    frames += 1
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

看起来 frame 变量是 None。即

_, frame = cap.read() # <- This fails for some reason.

您需要提供更多关于 cap 的信息,我们才能提供帮助。