Skip to content

Add line_width, show_labels, show_conf and show_boxes drawing options - #632

Merged
onuralpszr merged 2 commits into
mainfrom
draw-options
Nov 10, 2026
Merged

onuralpszr merged 2 commits into
mainfrom
draw-options

Conversation

@onuralpszr

@onuralpszr onuralpszr commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Adds line_width, show_labels, show_conf and show_boxes to the drawing options and the CLI, and draws boxes, labels, masks, pose and classification text the same way Python does. Checked side by side with Python for detect, segment, classify, pose and obb.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Added configurable box, label, confidence, and line-width drawing options to the annotation API and prediction CLI, with rendering updated to follow Ultralytics plot styling.

📊 Key Changes

  • Added line_width, show_boxes, show_labels, and show_conf to AnnotateOptions; defaults keep boxes, class names, and confidence visible, while line width is derived from image size unless set.
  • Added matching CLI flags and passed their values to annotations used for saved and displayed prediction results.
  • Unified box and oriented-box drawing, including label placement and line thickness; updated mask blending, pose line rendering, and classification text styling.
  • Updated English and Chinese documentation with the new options and annotation settings.

🎯 Purpose & Impact

  • Users can adjust annotation appearance from Python options or the CLI. Setting show_boxes to false skips box outlines and their labels, while segmentation masks are still drawn.

…and labels like Ultralytics

Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
@UltralyticsAssistant UltralyticsAssistant added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 10, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @onuralpszr, thank you for submitting a ultralytics/inference 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • ✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • ✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/inference main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • ✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • ✅ Update Documentation: Update the relevant documentation for any new or modified features.
  • ✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • ✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR; the CLA check will comment with signing instructions if needed.
  • ✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed the annotation rendering changes and their CLI wiring. The new controls are connected, but pose joints can be overwritten by skeleton lines and thick-label rendering adds a quadratic cost at common high-resolution image sizes.

💬 Posted 2 inline comments
  • 💡 MEDIUM src/annotate.rs:642 This rasterizes and composites the entire label once for every (dx, dy) pair, making label drawing quadratic in line width. For a 4K image, the default width is about 12, so every label takes 36 full text-render passes; frames with many detections can spend substantially more time annotating than before. Render the thickened glyphs in one pass or otherwise avoid repeating the full text draw for each offset.
  • 📝 LOW src/annotate.rs:852 This draws each keypoint circle before its skeleton limbs, so the limb is painted over the joint center and can replace the keypoint’s distinct palette color. The previous implementation drew limbs first; draw the limbs before the circles (or redraw the circles afterward).

@onuralpszr onuralpszr changed the title Add line_width, show_labels, show_conf and show_boxes and draw boxes and labels like Ultralytics Add line_width, show_labels, show_conf and show_boxes drawing options Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.65574% with 59 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/annotate.rs 80.39% 59 Missing ⚠️

📢 Thoughts on this report? Let us know!

…pass

Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 2

Made with ❤️ by Ultralytics Actions

The label thickening change addresses the prior performance finding. The pose draw order issue remains: skeleton lines can overwrite keypoint centers. Reviewed the annotation rendering and CLI wiring; no other concrete issues found.

💬 Posted 1 inline comment
  • 📝 LOW src/annotate.rs:902 With kpt_line enabled, the skeleton limbs are drawn after these circles, so each limb can overwrite the joint-center pixels with its limb color (and thicker limbs overwrite a strip of the joint). This loses the distinct keypoint palette colors; draw limbs first or redraw the circles afterward.

Comment thread src/annotate.rs Resolved
Comment thread src/annotate.rs Resolved

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 3

Made with ❤️ by Ultralytics Actions

Since review 2, the label-thickening performance issue is addressed; the pose draw order was explained as intentional parity and is not repeated. The annotation options and CLI wiring look sound, with one remaining OBB label-anchor regression noted above.

💬 Posted 1 inline comment
  • 📝 LOW src/annotate.rs:761 For OBBs, independently taking the minimum x and y can anchor the label at a different vertex from points[0] (at angle 0, it moves to the opposite corner). The previous OBB renderer anchored labels at corner 0, so rotated-box labels can now appear detached from their prior anchor. Use corner 0 for OBB labels and the minima for axis-aligned boxes.

Comment thread src/annotate.rs Resolved
Comment thread src/annotate.rs Resolved

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 4

Made with ❤️ by Ultralytics Actions

Since the last review, the thick-label performance issue is addressed; the pose draw order and OBB label anchor were explained as intentional Python parity and are not repeated. The new clipping guard drops partially visible pose limbs when a keypoint is off-frame. The remaining drawing-option and CLI wiring looks sound.

💬 Posted 1 inline comment
  • 📝 LOW src/annotate.rs:915 If either keypoint has a negative x or y coordinate, this skips the entire limb—even when part of it crosses the image and should be visible. draw_line already clips to the image bounds, so let it draw the segment rather than rejecting it here.

Comment thread src/annotate.rs Resolved
Comment thread src/annotate.rs Resolved

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 PR Review 5

Made with ❤️ by Ultralytics Actions

Since review 4, the earlier rendering findings are addressed or settled by the stated Python-parity behavior; the new drawing options and CLI wiring introduce no additional concrete issues. LGTM.

@onuralpszr
onuralpszr merged commit 7a96615 into main Nov 10, 2026
37 checks passed
@onuralpszr
onuralpszr deleted the draw-options branch November 10, 2026 12:48
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 This PR has been merged! Thank you, @onuralpszr, for adding configurable annotation styling to the API and CLI and aligning rendering across annotation types.

“Alone we can do so little; together we can do so much.” — Helen Keller

These options give users more control over how prediction results are displayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants