Docs
Docs pages

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

Vitals Solo, the solar pen camera, does this job end to end for ranchers. This recipe is for developers building their own tools.