Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

Bounding Box onto an Image

Bounding boxes are often used to highlight specific regions within an image, such as a face. Here we use the MLHub package azcv to obtain the bounding box of a face and to then annotate the image appropriately.

$ wget -O img.jpg \
https://upload.wikimedia.org/wikipedia/commons/thumb/7/72/\
Laurence_Freeman11.JPG/800px-Laurence_Freeman11.JPG

$ ml faces azcv img.jpg 
263 205 529 471,Male,58

$ ml faces azcv img1.jpg | tee img1.bb
263 205 529 471,Male,58

$ cat img.bb |
  cut -d, -f1 |
  xargs printf '-draw "rectangle %s,%s %s,%s" ' |
  awk '{print "img.jpg -fill none -stroke blue -strokewidth 3 " $0 "img_faces.png"}' |
  xargs convert

$ display img_faces.png

Figure 35.4: Using imagemagick to draw a bounding box onto an image.
Image imagemagick_bb

The photo used here was taken by Eugenio Hansen, OFS, CC BY-SA 3.0.


Copyright © 1995-2020 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.