Example Program (Bash)
A complete Bash script for detecting fish on images using the Fishial Recognition API.
Dependencies: bc, curl, jq, seq
Usage:
recognize_fish -k <API_KEY_ID> -s <API_SECRET_KEY> <picture-file>
Options:
| Flag |
Description |
-h, --help |
Print help and exit |
-k, --key-id |
Client key ID |
-s, --key-secret |
Client key secret |
Sample output:
Fishial Recognition has found 1 fish on the picture.
Fish 1 [137,326 758,495] is:
- Roach / Rutilus rutilus [certainty 97.00%]
- Rudd / Scardinius erythrophthalmus [certainty 10.0%]
This means: one fish detected with a bounding box from (137, 326) to (758, 495), matched to two species with the given certainty percentages (they do not necessarily sum to 100%).
Full script source
```bash
#!/usr/bin/env bash
set -euo pipefail
DEPENDENCIES=( bc curl jq seq )
print_help()
{
cat <
Note: this tool is not production grade. It lacks proper error checks, etc.
OPTIONS
-h, --help
Prints this message and exits.
-k, --key-id
Client key ID.
-s, --key-secret
Client key secret.
EXAMPLES
recognize_fish --help
recognize_fish -k abc123 -s abcd1234 fishpic.jpg
HELP
}
#### HELPERS ####
err()
{
echo "$1"
echo "In order to learn more, run: recognize_fish --help"
exit 1
}
extract_from_json()
{
jq --raw-output "$1" <<<"$2"
}
#### ENTRY POINT ####
#### PARSE ARGUMENTS ####
while test $# -gt 0
do
case "$1" in
-h|--help)
print_help
exit 0
;;
--key-id=*)
KEY_ID="${1#*=}"
shift
;;
-k)
KEY_ID="$2"
shift
shift
;;
--key-secret=*)
KEY_SECRET="${1#*=}"
shift
;;
-s)
KEY_SECRET="$2"
shift
shift
;;
*)
PICTURE="$1"
shift
;;
esac
done
#### CHECK ARGUMENTS ####
if ! [[ -f $PICTURE ]]; then
err "No picture file has been specified."
fi
#### CHECK DEPENDENCIES ####
for dep in ${DEPENDENCIES[*]}; do
if ! which -s "$dep"; then
err "Unsatisfied dependency: $dep"
fi
done
#### OBTAIN TOKEN ####
echo "Obtaining authorization token..."
echo
D=$(cat <