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 Union[Color, ColorPalette] to text_color parameter #1387

Merged
merged 14 commits into from
Jul 26, 2024

Conversation

Bhavay-2001
Copy link
Contributor

Description

Fix of issue #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?

I will update with colab notebook once the changes are approved.

Any specific deployment considerations

Docs

  • Docs updated? What were the changes:

@yeldarby
Copy link
Contributor

Nice! Probably also needs custom_text_color_lookup override

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, I have made the changes and this is the colab. Please let me know if anything is wrong and anything needs to be changed.

I have only changed the Label Annotator for now and will change the other two based if this is correct.

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, pls review this one.
Thanks

@@ -1050,6 +1055,7 @@ def annotate(
detections: Detections,
labels: Optional[List[str]] = None,
custom_color_lookup: Optional[np.ndarray] = None,
custom_text_color_lookup: Optional[np.ndarray] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use the same custom_color_lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 23, 2024

Hi 👋🏻 @yeldarby and @Bhavay-2001. I don't think we need custom_text_color_lookup.

The spirit behind custom_color_lookup is to override color_lookup while maintaining its consistent behavior. In the cases of ColorLookup.INDEX, ColorLookup.CLASS, or ColorLookup.TRACK, we utilize a single integer value to select a color with the same index from the color and text_color palettes. I believe the same approach should be adopted here. We should utilize custom_color_lookup to pick a color with the same index from the color and text_color palettes.

@Bhavay-2001 please apply these same changes to RichLabelAnnotator 🙏🏻

@@ -1369,7 +1382,7 @@ def annotate(
xy=(text_x, text_y),
text=text,
font=self.font,
fill=self.text_color.as_rgb(),
fill=text_color.as_rgb(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this, do we need to change as_rgb() to as_bgr() same like we did in LabelAnnotator?

Copy link
Collaborator

Choose a reason for hiding this comment

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

RichLabelAnnotator uses Pillow as a rendering engine. Pillow accepts colors in RGB order, while OpenCV in BGR. So we keep as_rgb() here.

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, please review the changes.

@Bhavay-2001
Copy link
Contributor Author

Also, if this gets approved, can I start with #1383? I would like to know more about the issue.
Thanks

@@ -1011,37 +1011,42 @@ class LabelAnnotator(BaseAnnotator):
def __init__(
self,
color: Union[Color, ColorPalette] = ColorPalette.DEFAULT,
text_color: Color = Color.WHITE,
text_color: Union[Color, ColorPalette] = ColorPalette.LEGACY,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small suggestion: I think we should keep white as default because it changes readability and also change default behavior, up until this version we put "white" and when people see different color It can create some confusion. It would be better keep "Color.WHITE" as default but keep type change is "Union[Color, ColorPalette]" in case of multi color change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@onuralpszr, yess certainly. I changed this because it was overlapping with ColorPalette.DEFAULT and the labels weren't visible but I will change it to White now.

Also, couldn't understand this but keep type change is "Union[Color, ColorPalette]" in case of multi color change. Can you explain it further? Thanks

Copy link
Collaborator

@onuralpszr onuralpszr Jul 25, 2024

Choose a reason for hiding this comment

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

@Bhavay-2001 What I meant is finally It should look like this

text_color: Union[Color, ColorPalette] = Color.WHITE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be wrong on this but I think there is no such method. Although, there is COLOR.WHITE

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Bhavay-2001 ah right I miss typed yes Color.WHITE

@Bhavay-2001
Copy link
Contributor Author

Hi @SkalskiP, this is open for reviewing now.

@@ -1369,7 +1382,7 @@ def annotate(
xy=(text_x, text_y),
text=text,
font=self.font,
fill=self.text_color.as_rgb(),
fill=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.

RichLabelAnnotator uses Pillow as a rendering engine. Pillow accepts colors in RGB order, while OpenCV in BGR. So we keep as_rgb() here.

text_scale: float = 0.5,
text_thickness: int = 1,
text_padding: int = 10,
text_position: Position = Position.TOP_LEFT,
color_lookup: ColorLookup = ColorLookup.CLASS,
text_color_lookup: ColorLookup = ColorLookup.CLASS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this parameter and use color_lookup.

font_path: Optional[str] = None,
font_size: int = 10,
text_padding: int = 10,
text_position: Position = Position.TOP_LEFT,
color_lookup: ColorLookup = ColorLookup.CLASS,
text_color_lookup: ColorLookup = ColorLookup.CLASS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this parameter and use only color_lookup.

@SkalskiP
Copy link
Collaborator

@Bhavay-2001, thanks a lot for all the work. We are almost there. Just few small changes and we can merge.

@Bhavay-2001
Copy link
Contributor Author

@Bhavay-2001, thanks a lot for all the work. We are almost there. Just few small changes and we can merge.

Done

@SkalskiP
Copy link
Collaborator

Tested here everything works. Merging!

@SkalskiP SkalskiP merged commit bb0e4ec into roboflow:develop Jul 26, 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.

4 participants