36.8 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 

Using imagemagick to draw a bounding box onto an image. {#graphics:fig:imagemagick_bb}

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



Your donation will support ongoing availability and give you access to the PDF version of the book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.