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

Conversation

souhhmm
Copy link
Contributor

@souhhmm souhhmm commented Dec 1, 2024

Fixes #275. Changed format to [x, y, width, height] as per NMSBoxes() and Rect_().

@souhhmm souhhmm changed the title fix: change to x,y,w,h format in NMSBoxes() [re] fix: change to x,y,w,h format in NMSBoxes() Dec 1, 2024
Copy link
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

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

Thank you for your fix! We can make use of RotatedRect instead. You could have a look below for more details.

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?

Copy link
Contributor Author

@souhhmm souhhmm Dec 13, 2024

Choose a reason for hiding this comment

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

Hey, yea although in vain. I've been encountering this error while trying to implement this.
Edit: To elaborate, as per the documentation, I'm passing three points to the constructor as follows:

rotated_rects = [
    cv.RotatedRect(tuple(det[0:2]), tuple(det[2:4]), tuple(det[4:6])) for det in dets
]

This is the error.

cv2.error: OpenCV(4.10.0) /io/opencv/modules/core/src/types.cpp:156: error: (-215:Assertion failed) std::fabs(vecs[0].ddot(vecs[1])) * a <= FLT_EPSILON * 9 * x * (norm(vecs[0]) * norm(vecs[1])) in function 'RotatedRect'


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/media/soham/New Volume/Projects 2/opencv_zoo/models/license_plate_detection_yunet/demo.py", line 121, in <module>
    results = model.infer(frame) # results is a tuple
              ^^^^^^^^^^^^^^^^^^
  File "/media/soham/New Volume/Projects 2/opencv_zoo/models/license_plate_detection_yunet/lpd_yunet.py", line 57, in infer
    results = self._postprocess(outputBlob)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/media/soham/New Volume/Projects 2/opencv_zoo/models/license_plate_detection_yunet/lpd_yunet.py", line 66, in _postprocess
    cv.RotatedRect(tuple(det[0:2]), tuple(det[2:4]), tuple(det[4:6])) for det in dets
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'cv2.RotatedRect'> returned a result with an exception set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fengyuentau Do you have any feedback on where I might be going wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

license_plate_detection_yunet NMSBoxes call with wrong bboxes
2 participants