Recipes
Wildlife: sort a card of camera-trap clips
A trail camera comes back with 400 clips, most of them wind in the grass. You want the ones with animals, with a count and what they were doing. Leans on detection Pending
import csv, pathlib
from vitalsbio import VitalsBio, InvalidRequestError
client = VitalsBio()
with open("card.csv", "w", newline="") as out:
w = csv.writer(out)
w.writerow(["clip", "animals", "species", "top_behaviours", "request_id"])
for clip in sorted(pathlib.Path("card").glob("*.mp4")):
try:
r = client.behavior(clip, max_seconds=15) # no species: detect any animal
except InvalidRequestError as e: # unreadable file, too large
w.writerow([clip.name, "", "", e.code, e.request_id]); continue
a = r["animals"]
w.writerow([clip.name, len(a), " ".join(sorted({x["species"] or "?" for x in a})),
" ".join(x["top"] or "?" for x in a), r.request_id])
What this can and can't tell you
- Species names come from a fixed list: cattle, horse, dog, sheep, goat, pig, cat, deer and other. Outside cattle, the detector is a general one trained on everyday photos, so it knows horses, sheep, dogs, cats, birds, bears, elephants, zebras and giraffes, and will miss or mislabel most other wildlife.
- A clip with zero animals still counts its seconds. Keep
max_secondslow for triage and rerun the keepers in full. - Night clips in infrared are not something any of the locked tests covered. Check a handful by eye before you trust a count.
- 400 clips at 10 requests a minute take about 40 minutes on Free. The client waits out the rate limit for you.
- Try it now:
client.behavior(sample="white-horses").