tryolabs / norfair

Lightweight Python library for adding real-time multi-object tracking to any detector.

Home Page:https://tryolabs.github.io/norfair/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

chrismatix opened this issue · comments

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,
            )