切片数组时出现“ TypeError:'NoneType'对象无法下标”

时间:2019-08-14 14:57:13

标签: python opencv

    cap = cv2.VideoCapture(video_path)
    ret , prev_frame = cap.read()
    count = 0
    while ret:
        ret , curr_frame = cap.read()
        a1 = curr_frame[:int(h/2-1),:int(w/2-1)]

错误:

a1 = curr_frame[:int(h/2-1), :int(w/2-1)]
TypeError: 'NoneType' object is not subscriptable

1 个答案:

答案 0 :(得分:0)

您可能要测试您的cap.read()语句。很明显,它返回了none结果。

cap = cv2.VideoCapture(video_path)
    ret , prev_frame = cap.read()
    count = 0
    while ret:
        ret , curr_frame = cap.read() or []
        a1 = curr_frame[:int(h/2-1),:int(w/2-1)]