簡體   English   中英

我有這段代碼,試圖通過捕獲視頻來運行社會隔離識別,但我有這個錯誤。 你可以幫幫我嗎?

[英]I have this code, trying to run a social isolation identification by capturing video, but I have this error. Could you help me?

我有這段代碼,試圖通過捕獲視頻來運行社會隔離識別,但我收到以下錯誤:

回溯(最近一次調用最后一次):文件“social_distance_detection.py”,第 127 行,在 cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2)到標量索引

你可以幫幫我嗎?

這是我正在運行的代碼:

for i in range(detections.shape[2]):

        confidence = detections[0, 0, i, 2]

        if confidence > args["confidence"]:

            class_id = int(detections[0, 0, i, 1])

            box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = box.astype('int')

            # Filtering only persons detected in the frame. Class Id of 'person' is 15
            if class_id == 15.00:

                # Draw bounding box for the object
                cv2.rectangle(frame, (startX, startY), (endX, endY), bounding_box_color[class_id], 2)

                label = "{}: {:.2f}%".format(labels[class_id], confidence * 100)
                print("{}".format(label))


                coordinates[i] = (startX, startY, endX, endY)



    for i in pos_dict.keys():
        if i in close_objects:
            COLOR = np.array([0,0,255])
        else:
            COLOR = np.array([0,255,0])
        (startX, startY, endX, endY) = coordinates[i]

        cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2)
        y = startY - 15 if startY - 15 > 15 else startY + 15
        # Convert cms to feet
        cv2.putText(frame, 'Depth: {i} ft'.format(i=round(pos_dict[i][2]/30.48,4)), (startX, y),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLOR, 2)

    cv2.namedWindow('Frame',cv2.WINDOW_NORMAL)

錯誤> https://i.stack.imgur.com/BZSZJ.jpg

您需要在矩形方法中將坐標轉換為 int。 使用 (int(startX,int(startY)) 相同的端點。

利用

for i in pos_dict.keys():
        if i in close_objects:
            COLOR = (0,0,255)
        else:
            COLOR = (0,255,0)

代替

for i in pos_dict.keys():
        if i in close_objects:
            COLOR = np.array([0,0,255])
        else:
            COLOR = np.array([0,255,0])

暫無
暫無

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

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