-
Notifications
You must be signed in to change notification settings - Fork 197
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Fixes #275. Changed format to [x, y, width, height] as per NMSBoxes() and Rect_().