-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
LineZoneAnnotator: Align text to line counter in non-horizontal lines #854
LineZoneAnnotator: Align text to line counter in non-horizontal lines #854
Conversation
Hi @jcruz-ferreyra 👋🏻 Thanks a lot of opening the new PR. |
Hi @SkalskiP! I was wondering if you've been able to check the PR |
Hi @jcruz-ferreyra 👋 Thanks for keeping the branch up to date. I've seen your contribution before. I think it's very high quality and I believe we'll have time to look deeper in about a week. Thanks again for an awesome contribution :) |
Hi @jcruz-ferreyra 👋 It's been a while, apologies for that. I'm planning to include this in the next supervision release. I'm happy to take over from this point onwards. Ahead of that, I moved some things around, cleaned up a few things. There's a few decisions to be made: 1. Is this too complicated?I cannot deny the visuals are perfect. It looks 10x better than what we had. However, the code is inevitably more cumbersome, and we probably want to move it to utils somewhere, or remove a few of these features. 2. Is this too slow?On a Colab, we can draw the new line zone 60 times a second, whereas previously we could do it 2000 times. At this point, realtime performance would be impacted, which I'd like to minimize. 3. Do we need the feature to draw off-center?It adds much code, and it wasn't widely requested so far. 4. Default code to non-centered.We should definitely default to the prior method when orientation is not required. It's more efficient. I'll park this for a few days and come back to finish it up later on. |
* Sped up computation from 600 fps to 1700 fps (Mac) * Previously ran at 2000 fps
Hi @LinasKo , I'm really glad you had the chance to review the pull request and found it interesting! I completely understand the concern regarding performance—it's unfortunate that OpenCV doesn't natively support drawing diagonal text. However, I still believe this functionality is crucial for non-standard use cases where lines need to be drawn in multiple directions. I also appreciate the improvements in code quality introduced in the latest commit. Please don't hesitate to let me know if there's anything I can do to assist you further with this. I'd be happy to contribute to any little thing I can, especially after all the help that Supervision has provided me with my CV tasks. |
Hey @jcruz-ferreyra 👋 I'm just putting a few finishing touches on the PR. I found ways to make the performance sane and the code more compact - we're keeping it, merging it, and retaining all the features you contributed 😉 Indeed, shame about OpenCV's lack of diagonality here. I've looked around, and everyone suggests a similar solution to what you added. Thank you for volunteering to help out! As for this PR, there's not much work left. I'll take over and get it done. Thank you for the contribution! 🚀 |
6c996d9
to
156dbd5
Compare
Leaving this for tomorrow. It feels like there's something slightly wrong with Docs are checked. Same Colab used for testing. Left to check: does commenting out the following code changes the distance between labels? Ideally it shouldn't. # Make sure text is displayed upright
if line_zone.vector.start.x > line_zone.vector.end.x:
label_image = cv2.flip(label_image, flipCode=-1) |
I've checked the docs, logic, code complexity and performance. Merging! Thank you for a high quality contribution, @jcruz-ferreyra! |
Hey @LinasKo, those are great news! I'm glad the contribution was well received. Here's my LinkedIn profile: |
Description
In this pull request, I've enhanced
LineZoneAnnotator
class insupervision/detection/line_counter.py
to align text with theLineZone
object even when it is non-horizontal.Additionally, I've introduced the option to omit drawing the text box behind the text, leveraging the optional condition on the
background_color
attribute in thedraw_text
method insupervision/draw/utils.py.
Furthermore, users can now choose whether to draw the count centered in theLineZone
object or aligned with its end, offering a solution to prevent overlaps in case of multiple LineZone objects in the same frame.Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
You can explore the results of the changes made in this Colab notebook. I've tested
LineZone
objects with varying orientations and positions within the frame, as well asLineZoneAnnotator
objects with different values for draw_text_box and draw_centered parameters.NOTE: Personally, I don't fully like the circles drawn at the extremes of the
LineZone
objects. However, I chose not to modify them to maintain conciseness in the pull request. Given the introduction of the newis_point_in_limits
method in theLineZone
class, it might be more effective to draw a small line perpendicular to the main line (or even nothing at all) to emphasize this new functionality.Any specific deployment considerations
No specific deployment considerations. Just one parameter added as an attribute for LineZone Class with default value "both" mantaining previous implementation.
Docs
No changes made to Docs