Skip to content

Instantly share code, notes, and snippets.

@berdosi
Last active July 24, 2019 19:19
Show Gist options
  • Save berdosi/31240dc22182e11887aa34b6cf576c21 to your computer and use it in GitHub Desktop.
Save berdosi/31240dc22182e11887aa34b6cf576c21 to your computer and use it in GitHub Desktop.
set image comment to labels detected via AWS
#!/bin/sh
MAXLABELCOUNT=4
MINCONFIDENCE=90
mkdir smallpics
# create smaller versions, that are both small and big enough for image recognition
parallel convert {} -resize 2048x2048 -quality 90 smallpics/{} ::: *.jpg
cd smallpics
for i in *.jpg; do
# fetch the labels from aws.
# the CLI's user has to have access to the rekognition API
aws rekognition detect-labels --image-bytes fileb://$i >> $i.labels.json;
# collect at most MAXLABELCOUNT comments with a set MINCONFIDENCE
comment=""
for ((labelIndex=0; labelIndex<MAXLABELCOUNT;labelIndex++)); do
confidence=`jq ".Labels[$labelIndex].Confidence" $i.labels.json`
if [ `echo $confidence'>'$MINCONFIDENCE | bc` -eq 1 ]
then
label=`jq ".Labels[$labelIndex].Name" $i.labels.json`
comment=$comment' '`echo $label | sed -e 's/"//g'`
fi
done
exiv2 -M"set Exif.Photo.UserComment charset=Ascii $comment" ../$i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment