Repository navigation
fix: #540 bug blur annotator - #555
Merged
Merged
Conversation
added 2 commits
October 30, 2023 10:26
Refactored the `clip_boxes` function for clarity by renaming arguments from `boxes_xyxy` and `frame_resolution_wh` to `xyxy` and `resolution_wh`, respectively. These change makes the function arguments more intuitive and improves code readability. The processing of detections in `supervision/annotators/core.py` has been updated to include clipping of detection boxes to the image bounds before processing. This prevents errors and ensures detections beyond the image dimensions are handled correctly. Adjustments were also made in the test cases and in `polygon_zone.py` to match the updated `clip_boxes` function.
Collaborator
|
Hi, @fdloopes 👋🏻 Thanks a lot for the time you spent debugging. I decided to use the I tested the fix, and it works! Merging! Thanks a lot 🙏🏻 for providing test colabs. It made my life a lot easier. |
SkalskiP
approved these changes
Oct 31, 2023
Author
|
Hi @SkalskiP 👋🏻 Right, I didn't know about the existence of the clip_boxes function, but I followed the commits you made and got up to speed on it, it makes more sense to actually use it than the solution I implemented. Glad to have helped! 😃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The coordinates of the detections object were found to have negative values in some cases, probably due to the trajectory prediction obtained with ByteTrack. Because of these negative coordinates, the ROI object was becoming null, which caused problems when calling cv2.blur(), as a valid array was expected.
The solution implemented for this bug was adjustment the command:
detections.xyxy[detection_idx].astype(int)To:
np.maximum(detections.xyxy[detection_idx].astype(int), 0)This way, whenever there is a negative coordinate, it will be mapped to 0.
Type of change
How has this change been tested, please provide a testcase or example of how you tested the change?
Google Colab Notebook: Example of the error occurring
Google Colab Notebook: Test with adjustment made
Any specific deployment considerations
I chose to make the adjustment within the BlurAnnotator.annotate() method because I imagine that in some scenarios ByteTrack returning negative coordinates may be interesting, such as multiple cameras and an object moving from one to another. However, this error may also occur for other annotators when using ByteTrack together.
I created two notebooks in colab, because after it imports a library it is not possible to make adjustments to it without resetting the environment, apparently it is preloaded in cache and the adjustments do not take effect.
Fix #540