簡體   English   中英

類型錯誤:'NoneType' object 不可下標

[英]Type error: 'NoneType' object is not subscriptable

我在 colab 上嘗試代碼,這是我的代碼的一部分

    while True:
            ret, frame = cap.read()
            if ret:
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                cls_idx = int(frames_label[frames_label['frame'] == i]['label'])
    
                if annot:
                    bb = np.array(annot.iloc[i-1, 2:].astype(int))
                else:
                     
                    bb = detector.detect(frame)[0, :4].numpy().astype(int)
                bb[:2] = np.maximum(0, bb[:2] - 5)
                bb[2:] = np.minimum(frame_size, bb[2:] + 5) if bb[2:].any() != 0 else bb[2:]

我還使用 imshow() 在我的屏幕上顯示圖片(由於代碼的長度,它不在上面的代碼中),圖片一開始可以正確顯示,但它會停在特定的圖片上,並提高

Type error: 'NoneType' object is not subscriptable at 

bb = detector.detect(frame)[0, :4].numpy().astype(int)

ps bb 是bounding box的縮寫

錯誤圖片:

錯誤圖像

有人可以幫忙嗎? 謝謝

我無法完全測試這一點,但進行這些更改並讓我知道它是否有效:

try:
    bb = detector.detect(frame)[0, :4].numpy().astype(int)
except Exception as e:
    print("An error occurred:", e)
    continue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM