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

print bounding box label text with draw_on_image #195

Open
namangt68 opened this issue Oct 11, 2018 · 3 comments
Open

print bounding box label text with draw_on_image #195

namangt68 opened this issue Oct 11, 2018 · 3 comments

Comments

@namangt68
Copy link

Hi, thanks for the useful library.

Right now we can print image with BBs using draw_on_image function as mentioned here also.
image_output = bbs.draw_on_image(image, thickness=2)
It would useful if we wil be able to print bounding box label string on the image using something like image_output = bbs.draw_on_image(image, thickness=2, print_label=True)

BoundingBox class already have label parameter.
class imgaug.imgaug.BoundingBox(x1, y1, x2, y2, label=None)

@aleju
Copy link
Owner

aleju commented Oct 11, 2018

Seems reasonable. I added it to the TODO list.

aleju added a commit that referenced this issue Jan 1, 2020
This patch adds automatic drawing of BB labels upon
calls of `BoundingBox.draw_on_image()` and
`BoundingBoxesOnImage.draw_on_image()`.

This resolves issues #519 and #195.

* Add method `imgaug.augmentables.BoundingBox.draw_label_on_image()`.
* Add method `imgaug.augmentables.BoundingBox.draw_box_on_image()`.
* Change method `imgaug.augmentables.BoundingBox.draw_on_image()`
  to automatically draw a bounding box's label.
@lmolhw5252
Copy link

How to set label in chinese? I had try it but chinese is not normal display!

@aleju
Copy link
Owner

aleju commented Mar 4, 2020

imgaug currently uses PIL's text drawing function with a custom font file, saved under under imgaug/DejaVuSans.ttf. I doubt that the file contains any chinese characters. It's probably limited to ASCII. The path to the ttf file is set in imgaug.imgaug.DEFAULT_FONT_FP. You could try to replace it by another font file containing chinese characters, e.g. imgaug.imgaug.DEFAULT_FONT_FP = "/path/to/some/file.ttf". (Not sure though if these characters can be saved in ttf files or if PIL's drawing function supports non-ASCII characters.)

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

No branches or pull requests

3 participants