我正在尝试使用在Darknet YOLO上训练的模型来使用OpenCV DNN模块检测对象。以下是令人关注的摘要。所有必需的库均已导入。
# Create a 4D blob from a frame.
blob = cv.dnn.blobFromImage(frame, 1/255, (inpWidth, inpHeight), [0,0,0], 1, crop=False)
# Sets the input to the network
net.setInput(blob)
# Runs the forward pass to get output of the output layers
outs = net.forward()
rects = []
#Tracker code
for i in range(0, outs.shape[2]):
# filter out weak detections by ensuring the predicted
# probability is greater than a minimum threshold
if outs[0, 0, i, 2] > args['confidence']:
print (outs[0,0,i,2])
# compute the (x, y)-coordinates of the bounding box for
# the object, then update the bounding box rectangles list
box = outs[0, 0, i, 3:7] * np.array([frame.shape[1], frame.shape[0], frame.shape[1], frame.shape[0]])
rects.append(box.astype("int"))
# draw a bounding box surrounding the object so we can
# visualize it
(startX, startY, endX, endY) = box.astype("int")
cv2.rectangle(frame, (startX, startY), (endX, endY),
(0, 255, 0), 2)
此部分引发以下错误:
for i in range(0, outs.shape[2]):
IndexError: tuple index out of range
从网络获得的检测结果需要进行循环,以过滤掉具有低置信度得分的检测结果。 “输出”数组存储所有宽松的检测坐标。
在这种情况下,请帮助找出为什么元组索引超出范围?