Ask Your Question
0

How to find edge pixel coordinates at corners of the bounding box [closed]

asked 2018-03-01 20:09:00 -0600

krishnapra gravatar image

updated 2018-03-01 23:07:52 -0600

berak gravatar image

I am using dnn module of opencv for object detection in tensorflow. I want to know how to find pixel coordinates (x,y) at corners of bounding box of detected object as highlighted in blue on image below.

image description

I use below snippet for drawing bounding boxes, which is from opencv dnn samples

    cols = frame.shape[1]
    rows = frame.shape[0]

    for i in range(detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        if confidence > args.thr:
            class_id = int(detections[0, 0, i, 1])

            xLeftBottom = int(detections[0, 0, i, 3] * cols)
            yLeftBottom = int(detections[0, 0, i, 4] * rows)
            xRightTop   = int(detections[0, 0, i, 5] * cols)
            yRightTop   = int(detections[0, 0, i, 6] * rows)

            cv.rectangle(frame, (xLeftBottom, yLeftBottom), (xRightTop, yRightTop),
                          (0, 255, 0))
            if class_id in classNames:
                label = classNames[class_id] + ": " + str(confidence)
                labelSize, baseLine = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1)

                yLeftBottom = max(yLeftBottom, labelSize[1])
                cv.rectangle(frame, (xLeftBottom, yLeftBottom - labelSize[1]),
                                     (xLeftBottom + labelSize[0], yLeftBottom + baseLine),
                                     (255, 255, 255), cv.FILLED)
                cv.putText(frame, label, (xLeftBottom, yLeftBottom),
                            cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))

    cv.imshow("detections", frame)
    if cv.waitKey(1) >= 0:
        break
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by krishnapra
close date 2018-03-03 03:25:41.884884

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-03-01 21:20:11 -0600

Tetragramm gravatar image

So, uh, you see that code? You see the part labelled xLeftBottom, yLeftBottom, xRightTop, yRightTop? That's them.

The two points on the left side of the box share the same x, the points on the top share the same y, ect...

edit flag offensive delete link more

Comments

@Tetragramm Yes i was printing xLeftBottom, yLeftBottom, xRightTop, yRightTop but not able to interpret properly. Now got clear information. Thank you!

krishnapra gravatar imagekrishnapra ( 2018-03-01 21:36:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-01 20:09:00 -0600

Seen: 3,451 times

Last updated: Mar 01 '18