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

Added text_color parameter for VertexLabelAnnotator #1409

Merged
merged 16 commits into from
Aug 14, 2024

Conversation

Bhavay-2001
Copy link
Contributor

@Bhavay-2001 Bhavay-2001 commented Jul 26, 2024

Description

Part of #1384

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

  1. Notebook

Any specific deployment considerations

For example, documentation changes, usability, usage/costs, secrets, etc.

Docs

  • Docs updated? What were the changes:

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, I have made the changes as per my understanding. In the VertexLabel class, it is running a for loop for different colors where there should be for text color too here

Soo I think it should add some function for adding multiple text_colors

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP @LinasKo pls review this PR.
Thanks

@SkalskiP SkalskiP mentioned this pull request Aug 5, 2024
4 tasks
@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 5, 2024

Hi, @Bhavay-2001 👋🏻 Thanks a lot for your interest in supervision. It Looks like you added external API and docstring, but it looks like changing the value of text_color does not result in changing the text color per anchor :/ Am I missing something?

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, Yess, this was little bit incomplete.

The color parameter of the VertexLabelAnnotator is Union[Color, List[Color]]. Should we add this in text_color as well soo that we can use the same logic as in the color parameter?

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 6, 2024

Hi @Bhavay-2001 👋🏻 I'd even say we should make it the same as other annotators and make both color and text_color to be Union[Color, ColorPalette].

@Bhavay-2001
Copy link
Contributor Author

Alright. Then, maybe we should take the this logic from other annotators.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 6, 2024

If it's possible to reuse some parts of that logic, then sure.

@Bhavay-2001
Copy link
Contributor Author

Before making the changes, I would like to discuss regarding this.

Currently, the color parameter in VertexLabelAnnotator accepts either single color or a list. If we change it to ColorPallette, then we need to make changes to this function -

def preprocess_and_validate_colors(
        colors: Optional[Union[Color, List[Color]]],
        points_count: int,
        skeletons_count: int,
    ) -> np.array:
        if isinstance(colors, list) and len(colors) != points_count:
            raise ValueError(
                f"Number of colors ({len(colors)}) must match number of key points "
                f"({points_count})."
            )
        return (
            np.array(colors * skeletons_count)
            if isinstance(colors, list)
            else np.array([colors] * points_count * skeletons_count)
        )

In this, we need to change the color parameter in function definition and then it will return a list of colors. Should I proceed with this?

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 7, 2024

@Bhavay-2001, after further consideration, let's not change the type for now. Keep color as either Color or List[Color] (let's not introduce ColorPalette yet). But let's make text_color also Color or List[Color].

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, please check the code and the notebook.
Thanks

Copy link
Collaborator

@LinasKo LinasKo left a comment

Choose a reason for hiding this comment

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

Hi @Bhavay-2001,

I left one comment in the code.

You've also added 2 images. Please remove those.

supervision/keypoint/annotators.py Outdated Show resolved Hide resolved
@@ -321,12 +323,19 @@ def annotate(
skeletons_count=skeletons_count,
)

text_colors = self.preprocess_and_validate_text_colors(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LinasKo, Should I call the preprocess_and_validate_colors method here too to get the list of text_colors then?

@Bhavay-2001
Copy link
Contributor Author

Done

@@ -357,7 +368,7 @@ def annotate(
org=(box[0], box[3]),
fontFace=font,
fontScale=self.text_scale,
color=self.text_color.as_rgb(),
color=text_color.as_rgb(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be as_bgr. OpenCV has a blue-green-red ordering of colors. You can find that we call other opencv functions similarly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes right. I have changed this code some place else too. Missed here sorry.

@LinasKo
Copy link
Collaborator

LinasKo commented Aug 14, 2024

Hi @Bhavay-2001, I've now approved the pull request and will merge it in. Thank you for the contribution.

However, it is also an example of a contribution we won't accept in the future. For a feature this small, the number of times we had to come back to verify, the number of mistakes we found, the number of questions we had to answer - that takes 5x time than it saves, especially for a feature this small. Looking back, this also holds true for #1387 and #1227.

@LinasKo LinasKo merged commit 822dd4d into roboflow:develop Aug 14, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants