Reputation: 31
Running predictions with https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb.
Linux Ubuntu 16.04
Would like to customize label font size & bounding box thickness as my label text & bbox are too thick in image detections.
Thank you for any help! If you have done this yourself please pass along your learnings! :)
Upvotes: 3
Views: 7418
Reputation: 41
To change font size:
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.
Upvotes: 4
Reputation: 22807
Ubuntu 16.04 seemingly does not ship with the arial.ttf
font - and this is unfortunately what vis_util.visualize_boxes_and_labels_on_image_array
uses by default and it is not configurable except by changing the python code. When it can't find that font it uses a default bitmap font, however the resolution is too low for many purposes, especially at low DPI settings.
However you can workaround this problem in a number of ways:
sudo apt-get install ttf-mscorefonts-installer
(this however did not work for me - not sure why)DejaVuSans.ttf
to a file with the name arial.ttf
in the directory /usr/share/fonts/truetype/dejavu
DejaVuSans.ttf
to a file with the name arial.ttf
in your object_detection
directory (assuming you are running your code there)Then you can visualize your boxes and labels with DPI=100
and still read the font.
Before - 100 DPI with the default bitmap font:
After - 100 DPI with arial.ttf
Upvotes: 3
Reputation: 135
You can change the bounding boxes thickness by changing the line_thickness
parameter in the visualize_boxes_and_labels_on_image_array
as follows:
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
Upvotes: 4