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
[RichLabelAnnotator] - add support for unicode labels #990
Comments
Hi @Ying-Kang 👋🏻, thanks for your interest in supervision. We initially wanted to add support for Unicode labels, but we ultimately became overwhelmed by the work involved in working around other annotators and decided to limit the scope. I think it would be a good idea to revisit this idea now. We already have the framework ready we would just have to add this new functionality. |
Hi @Ying-Kang 👋🏻 I'll keep it open if that's okey with you. |
Hi 👋, I'd like to try working on this. |
Hi @jeslinpjames 👋🏻 ! I assigned the issue to you. Good luck! |
I did research previously, to use "Unicode" support to visualize Opencv we need to make sure it needs to be compiled with extra parameters (PIP version of OpenCV-python doesn't enable it because of licensing) but in the next version of OpenCV (5.0) will change and enable by default. They will introduce TrueType font support (opencv/opencv#18760) and I noticed they are using "Rubik" font and support many languages as well. For Pillow, we need to use an external font file based on OpenCV's choice maybe we can use that font until they release version 5.0. That's all I saw and see for now. I hope that helps bit more in case to find something as well. |
Hi @SkalskiP, 🙌 Thanks for the assignment! And @onuralpszr, appreciate the info on Unicode support. |
Hi @onuralpszr, Initially, I attempted to use the Rubik-regular.ttf font file, but it didn't effectively support all languages. Then, I found that the Arial Unicode Font.ttf file provides better support for a wide range of languages. I also had a question regarding the default value for the Here's the updated snippet of the class RichLabelAnnotator:
def __init__(
self,
color: Union[Color, ColorPalette] = ColorPalette.DEFAULT,
text_color: Color = Color.WHITE,
font_path: str = None,
font_size: int = 10,
text_padding: int = 10,
text_position: Position = Position.TOP_LEFT,
color_lookup: ColorLookup = ColorLookup.CLASS,
border_radius: int = 0,
):
self.color = color
self.text_color = text_color
self.text_padding = text_padding
self.text_anchor = text_position
self.color_lookup = color_lookup
self.border_radius = border_radius
if font_path is not None:
try:
self.font = ImageFont.truetype(font_path, font_size)
except OSError:
print(f"Font path '{font_path}' not found. Using a system font.")
self.font = ImageFont.load_default(size=font_size)
else:
self.font = ImageFont.load_default(size=font_size) Please let me know if any further adjustments are needed. |
Hello @jeslinpjames What do you mean by using "system font"? Are you going to use font from OS (Linux, Windows, macOS) or use font from Pillow, OpenCV font? I am debating whether should we even need RichLabelAnnotator maybe we can consider making the change to labelAnnotator and If you provide a font path it will just use that font and no try except require plus less code work. Another part I am thinking of is maybe we can also create another subpackage for supervision addon to provide fonts in Python package by installing via pip and without manually typing the full path of the font (but the license needs to be checked) @SkalskiP @LinasKo what do you guys think? Should we extend our LabelAnnotator or add a completely new annotator? |
The font provided by Pillow, and I've almost completed the |
I like Onuralp's idea about merging this with the standard label annotator, but I don't know whether that would break anything in systems currently in use. If we can apply these changes to |
Here is the Google Colab link: Google Colab Notebook |
I'll see if I can review in the next few days. |
If you may I can handle it |
I just need opinion about merge into label without api break or separate annotator that's all |
That would be most helpful :)
I'll try to find the time tomorrow. |
My believe we can handle without api break and just one extra if statement needed if font stated without font it is gonna use what we have so, we can do minimal change as well |
@jeslinpjames please open PR for RichLabelAnnotator as a new Annotator, take out "resolve_text_background_xyxy" and put utils.py both LabelAnnotators should be able to use it. Let's continue to rest in PR |
Description
LabelAnnotator
uses OpenCV as a rendering engine. Unfortunately,cv2.putText
, which we use underneath, only supports ASCII characters. A solution to this problem would be the implementation of a new annotator that adds support for Unicode characters based on Pillow.We previously considered a similar idea, but we decided not to implement it due to time constraints. #159
API
Additional
The text was updated successfully, but these errors were encountered: