models icon indicating copy to clipboard operation
models copied to clipboard

How to increase the font size of the bounding box in Tensorflow object detection module?

Open biranchi2018 opened this issue 9 years ago • 11 comments

I have increased the font size to 30 from the default size 24 inside the draw_bounding_box_on_image() in visualization_utils.py

font = ImageFont.truetype('arial.ttf', 30)

But still the font size is not getting changed.

object detection

biranchi2018 avatar Oct 26 '17 09:10 biranchi2018

i found the issue. On Mac we need to give the full path. ImageFont.truetype('/Library/Fonts/Arial.ttf', 30)

biranchi2018 avatar Oct 26 '17 10:10 biranchi2018

Yes! This happens because it falls back on the default font, for which you cannot set size. Another option, if you don't want to change the source code, is to put the arial.ttf font file in the directory where you're running that code.

Let's use StackOverflow for further support, so the devs here can focus on bugs. Since you've found the answer yourself, you would've gained at least 20 rep on SO 😃

cipri-tom avatar Oct 26 '17 14:10 cipri-tom

@afixibiranchi I alos use mac , and i change it to the full path. but it still don't work ...

cindysillence avatar Nov 29 '17 13:11 cindysillence

It works for me. Copy font to folder with script

cp /Library/Fonts/Arial.ttf Arial.ttf

and in script:

ImageFont.truetype('./Arial.ttf', 30)

Alykoff avatar Dec 09 '17 10:12 Alykoff

Anyone know the solution to this for Windows? Where is Arial.ttf located?

dburns7 avatar Oct 07 '18 22:10 dburns7

Hi,

Solution is simple: in file models/research/object_detection/utils/visualization_utils.py starting from line 202:

  try:
    font = ImageFont.truetype('arial.ttf', 24)
  except IOError:
    font = ImageFont.load_default()

Here we just need to change number 24 to desired font size.

LjuboM avatar Jul 21 '19 16:07 LjuboM

Did everything suggested here. still not working. I am using amazon ec2 instance. Funny thing is I having added print statements in Visualisation_utils.py but its not event printing anything. Anything I am missing? Also I am using Zeppelin notebook if that can play any role in this.

Update: I resolved the issue. It seems like the python file Visualisation_utils.py was cached. I restarted the interpreter and it worked like a charm. I had to change the font with full path though.

sahilshaikh89 avatar Jul 21 '19 22:07 sahilshaikh89

I had to install ttf-mscorefonts. Ubuntu 18.04

sudo apt-get install ttf-mscorefonts-installer
sudo fc-cache
fc-match Arial

Should show: Arial.ttf: "Arial" "Regular"

seth814 avatar Jul 23 '19 00:07 seth814

I had the same issue, doing what seth814 suggested worked for me. I am also using Ubuntu 18.04. downloaded about 240KB of font data if u like to know space needed.

Thanks.

rbtirumala avatar Oct 22 '20 22:10 rbtirumala

@Annieliaquat in your try block, you should assign to font variable: font = ImageFont.truetype('/Library/Fonts/Arial.ttf', 24). Make sure the path is valid

cipri-tom avatar Feb 21 '22 13:02 cipri-tom

@Annieliaquat NO, stop spamming this issue ! Create another one or ask on stackoverflow

cipri-tom avatar Feb 25 '22 13:02 cipri-tom