Mat[0,0,i,2] 函数在 Python 中用 OpenCV 做什么

问题描述 投票:0回答:0

我正在尝试理解这段代码并将其转换为 Java

代码来自本教程,完整代码片段如下所示 https://pyimagesearch.com/2017/09/11/object-detection-with-deep-learning-and-opencv/

我要转换线

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

detections
是 OpenCV Mat 类,由
net.forward()

返回

首先我要明白这是什么意思

这是投资回报率吗?为什么会有4个值的数组,它们代表什么?

接下来,这行代码在Java中会是什么样子?

此外,这一行读起来非常混乱

box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])

什么意思,如何转换成Java?

# pass the blob through the network and obtain the detections and
# predictions
print("[INFO] computing object detections...")
net.setInput(blob)
detections = net.forward()

# loop over the detections
for i in np.arange(0, detections.shape[2]):
    # extract the confidence (i.e., probability) associated with the
    # prediction
    confidence = detections[0, 0, i, 2]
    # filter out weak detections by ensuring the `confidence` is
    # greater than the minimum confidence
    if confidence > args["confidence"]:
        # extract the index of the class label from the `detections`,
        # then compute the (x, y)-coordinates of the bounding box for
        # the object
        idx = 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")
        # display the prediction
        label = "{}: {:.2f}%".format(CLASSES[idx], confidence * 100)
        print("[INFO] {}".format(label))
        cv2.rectangle(image, (startX, startY), (endX, endY),
            COLORS[idx], 2)
        y = startY - 15 if startY - 15 > 15 else startY + 15
        cv2.putText(image, label, (startX, y),
            cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2)
python java android opencv
© www.soinside.com 2019 - 2024. All rights reserved.