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

Created on 26 Oct 2017  路  9Comments  路  Source: tensorflow/models

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

Most helpful comment

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"

All 9 comments

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

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 馃槂

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

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)

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

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.

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.

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"

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.

Was this page helpful?
0 / 5 - 0 ratings