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

Multiple Annotation Type Option #370

Closed
2 tasks done
sanaullah-06 opened this issue Sep 20, 2023 · 8 comments
Closed
2 tasks done

Multiple Annotation Type Option #370

sanaullah-06 opened this issue Sep 20, 2023 · 8 comments
Assignees
Labels
api:annotator Annotators enhancement New feature or request

Comments

@sanaullah-06
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Description

Currently Supervision can only draw rectangles as an annotation. It would be cool if we add option for drawing circle, triangle, polygon etc.
aa52476a-ead3-4661-934c-29f2f1d6f6a2
e3baae74-6f0e-4c2d-9064-9039a8925a90
44357787-38e6-4244-972a-dc2a1e74dfa0

Use case

Sometime Rectangle makes annotations looks messy. So need other means for annotations

Additional

I am new to contributions so be humble with me ! haha

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@sanaullah-06 sanaullah-06 added the enhancement New feature or request label Sep 20, 2023
@github-actions
Copy link
Contributor

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.

@SkalskiP SkalskiP self-assigned this Sep 26, 2023
@SkalskiP
Copy link
Collaborator

Hi, @sanaullah-code 👋🏻! I'm sorry for such a late response. I've been on vacation for the past two weeks and now I'm trying to catch up.

I like your idea very much! We have been thinking about adding more annotators for a while. I noticed that you checked "Yes, I'd like to help by submitting a PR!". How about getting started with TriangleAnnotator?

@sanaullah-06
Copy link
Author

I would love to start it or you can say I have already worked on it however need some suggestion from you like currently we have BoxAnnotator Class which have the annotate method/function so, we can do it in two ways

1- A whole new TriangleAnnotator class same as the BoxAnnotator

2- We can give parameter in the annotate method e.g annotation_type and it might be like circle triangle etc

`def annotate(
self,
scene: np.ndarray,
detections: Detections,
labels: Optional[List[str]] = None,
skip_label: bool = False,
annotation_type: str = "rectangle", # Default to drawing rectangles

) -> np.ndarray:
   
    font = cv2.FONT_HERSHEY_SIMPLEX
    for i in range(len(detections)):
        x1, y1, x2, y2 = detections.xyxy[i].astype(int)
        class_id = (
            detections.class_id[i] if detections.class_id is not None else None
        )
        idx = class_id if class_id is not None else i
        color = (
            self.color.by_idx(idx)
            if isinstance(self.color, ColorPalette)
            else self.color
        )
        if annotation_type == "rectangle":
            # Draw rectangles
            cv2.rectangle(
                img=scene,
                pt1=(x1, y1),
                pt2=(x2, y2),
                color=color.as_bgr(),
                thickness=self.thickness,
            )
        elif annotation_type == "pointer":
            # Draw pointers (dots)
            cv2.circle(
                img=scene,
                center=((x1 + x2) // 2, (y1 + y2) // 2),  # Center of the box
                radius=self.pointer_radius,
                color=color.as_bgr(),
                thickness=cv2.FILLED,
            )
        elif annotation_type == "circle":
            # Draw circles
            center_x = (x1 + x2) // 2
            center_y = (y1 + y2) // 2
            radius = max((x2 - x1) // 2, (y2 - y1) // 2)
            cv2.circle(
                img=scene,
                center=(center_x, center_y),
                radius=radius,
                color=color.as_bgr(),
                thickness=self.thickness,
            )
        if skip_label:
            continue

        text = (
            f"{class_id}"
            if (labels is None or len(detections) != len(labels))
            else labels[i]
        )

        text_width, text_height = cv2.getTextSize(
            text=text,
            fontFace=font,
            fontScale=self.text_scale,
            thickness=self.text_thickness,
        )[0]

        text_x = x1 + self.text_padding
        text_y = y1 - self.text_padding

        text_background_x1 = x1
        text_background_y1 = y1 - 2 * self.text_padding - text_height

        text_background_x2 = x1 + 2 * self.text_padding + text_width
        text_background_y2 = y1

        cv2.rectangle(
            img=scene,
            pt1=(text_background_x1, text_background_y1),
            pt2=(text_background_x2, text_background_y2),
            color=color.as_bgr(),
            thickness=cv2.FILLED,
        )
        cv2.putText(
            img=scene,
            text=text,
            org=(text_x, text_y),
            fontFace=font,
            fontScale=self.text_scale,
            color=self.text_color.as_rgb(),
            thickness=self.text_thickness,
            lineType=cv2.LINE_AA,
        )
    return scene`

just tell me which one you would prefer and hope you enjoyed your vacations

@onuralpszr
Copy link
Collaborator

@sanaullah-code

#372
#170 (this is big one)

we are having a huge change for annotators, first let's merge this two, then we can work on others

@sanaullah-06
Copy link
Author

sanaullah-06 commented Sep 26, 2023

@onuralpszr why we are not making it easier just giving a parameter of annotation_type? it would be more easier for the user though.

@SkalskiP
Copy link
Collaborator

Hi @sanaullah-code 👋🏻 Please create the whole TriangleAnnotator class.

@sanaullah-06
Copy link
Author

great i will create a PR to TriangleAnnotator.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Oct 3, 2023

Hi @onuralpszr and @sanaullah-code, I created separate issues for different annotators:

I'm closing this issue. Let's move the conversation to specific issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:annotator Annotators enhancement New feature or request
Projects
Status: Current Release: Done
Development

No branches or pull requests

3 participants