Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[re] fix: change to x,y,w,h format in NMSBoxes() #280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion models/license_plate_detection_yunet/lpd_yunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ def infer(self, image):
def _postprocess(self, blob):
# Decode
dets = self._decode(blob)

# convert to x, y, w, h format
bboxes = np.zeros((dets.shape[0], 4))
bboxes[:, 0] = np.min(dets[:, [0, 2, 4, 6]], axis=1) # top-left x
bboxes[:, 1] = np.min(dets[:, [1, 3, 5, 7]], axis=1) # top-left y
bboxes[:, 2] = np.max(dets[:, [0, 2, 4, 6]], axis=1) - bboxes[:, 0] # width
bboxes[:, 3] = np.max(dets[:, [1, 3, 5, 7]], axis=1) - bboxes[:, 1] # height
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually NMSBoxes supports RotatedRect (See https://docs.opencv.org/4.x/d6/d0f/group__dnn.html#gaeec27cb32195e71e6d88032bda193162). So there is no need to de-rotate the boxes.

self._decode returns a set of four corners points but RotatedRect only needs three points for constructor (See https://docs.opencv.org/4.x/db/dd6/classcv_1_1RotatedRect.html). So try to remove one set of a corner point from dets and make it being initialized as RotatedRect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@souhhmm Do you have updates on this?


# NMS
keepIdx = cv.dnn.NMSBoxes(
bboxes=dets[:, 0:4].tolist(),
bboxes=bboxes.tolist(),
scores=dets[:, -1].tolist(),
score_threshold=self.confidence_threshold,
nms_threshold=self.nms_threshold,
Expand Down