Recipes
Ranching: who lay down all afternoon?
A pen camera records all afternoon. You want a short list of animals that barely got up, to walk past and look at. Leans on behaviour Live
from collections import defaultdict
from vitalsbio import VitalsBio
client = VitalsBio()
lying = defaultdict(float); seen = defaultdict(float)
# barn.mp4 or rtsp://pen-camera/1; one call per 10 s segment
for seg in client.stream("pen-afternoon.mp4", endpoint="behavior", segment_seconds=10, species="cattle"):
for a in seg["animals"]:
key = (seg["stream"]["segment_index"], a["track_id"]) # track numbers restart each segment
for f in a["frames"]:
seen[key] += 1
lying[key] += f["behaviour"]["lying"]
for key in sorted(seen, key=lambda k: -lying[k] / seen[k])[:10]:
print(key, f"lying {lying[key] / seen[key]:.0%} of {seen[key]:.0f} frames")
What this can and can't tell you
- It tells you how much of each segment each tracked animal spent lying. Lying a lot is a reason to look, not a finding.
- It can't follow one cow across segments or days yet. Track numbers restart in every segment, and identity Pending has not passed its test. For now, treat each segment's list as "an animal at this spot".
/v1/health-scorereturnsnullfor every animal today, because no state reading is validated. Don't build an alert on it yet.- Try it now with no video:
client.behavior(sample="cow-lying")shows four cattle, each lying for more than 95% of the clip.
Vitals Solo, the solar pen camera, does this job end to end for ranchers. This recipe is for developers building their own tools.