gpt4 book ai didi

python - 我有这段代码,试图通过捕获视频来运行社交隔离标识,但是我遇到此错误。你可以帮帮我吗?

转载 作者:行者123 更新时间:2023-12-02 16:33:53 25 4
gpt4 key购买 nike

我有以下代码,试图通过捕获视频来运行社交隔离标识,但是出现以下错误:

Traceback (most recent call last): File "social_distance_detection.py", line 127, in cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2) TypeError: only integer scalar arrays can be converted to a scalar index



你可以帮帮我吗?

这是我正在运行的代码:
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)

错误> /image/BZSZJ.jpg

最佳答案

您需要将坐标转换为int矩形方法。端点使用(int(startX,int(startY))相同。

关于python - 我有这段代码,试图通过捕获视频来运行社交隔离标识,但是我遇到此错误。你可以帮帮我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61548705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com