0
$\begingroup$

In some of the OpenCV implementations for object detection , I don't understand how the co-ordinates of the bounding box of an object are extracted from the image.

For example , In Object Detection using Deep Learning

There is a snippet of code I don't understand .

# 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)

In the line , box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) , Can someone please tell me why we multiply with the width and height of the image to get the co-ordinates of the box ? Doesn't the output detections[] itself give the co-ordinates ?

Now , my questions are , If 'detections' doesn't directly output the co-ordinates , what else does it output ?

And , Why is it required to multiply with the width and height of the image ?

Can someone please clear my doubts in a simple and effective manner ?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.