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

Text disappears when the top of the prediction box is too close to the top of the frame #284

Open
chrismatix opened this issue Nov 14, 2023 · 0 comments
Labels
feature request New feature or request

Comments

@chrismatix
Copy link

Is your feature request related to a problem? Please describe.

When using draw_boxes with a prediction that has a y value that is close to the top of the box the text will either get clipped or disappear entirely.

Describe the solution you'd like

Only when this happens should the text be rendered on the inside of the box.

Describe alternatives you've considered
I have copied the function to my code and addressed this which is a workaround, but I think the library should generally support this case:

            # If the box is too close to the top of the frame, draw the text
            # on the inside of the box instead of the outside
            text_x_anchor = points[0, 0] - thickness // 2
            text_y_anchor = points[0, 1] - thickness // 2 - 1
            if text_y_anchor < 0:
                text_dimensions, _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, text_size, text_thickness)
                text_y_anchor = points[0, 1] + thickness // 2 + int(text_dimensions[1]) + 1

            text_anchor = (text_x_anchor, text_y_anchor)

            frame = Drawer.text(
                frame,
                text,
                position=text_anchor,
                size=text_size,
                color=obj_text_color,
                thickness=text_thickness,
            )
@chrismatix chrismatix added the feature request New feature or request label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant