Real-time AI pig counting: a PoC for herd tracking via camera, 95-98% accuracy at gate crossing

Edge/Camera API AI Automation OCR 2026
Real-time AI pig counting: a PoC for herd tracking via camera, 95-98% accuracy at gate crossing

Project Context

Counting and tracking pig numbers on a farm is a repetitive daily task, done manually or by reviewing camera footage: slow, error-prone at scale, and unable to flag a discrepancy the moment it happens. VAON built a proof-of-concept using existing camera hardware to detect, track and count pigs in real time, as the technical foundation for an AI-based farm monitoring solution.

Challenges

1

Manual counting is slow and error-prone at scale

Counting by eye or reviewing camera footage costs staff time every day, and accuracy drops sharply as herd size grows or pigs move continuously. A count discrepancy is usually discovered after the fact, not the moment it occurs.

2

Occlusion in a crowded pen is the hardest problem in livestock computer vision

An overhead camera looking down on a crowded pen sees animals constantly overlapping and occluding one another. This is the hardest condition for any vision-based counting system, not unique to pigs. A partially occluded animal can be missed or double-counted when it reappears.

3

"Accurate count" and "anomaly monitoring" need to stay distinct

Not every scenario needs an absolute number. In a crowded pen, the real value is detecting a deviation from the previous count (an early alert on something unusual), which matters more than an exact figure that occlusion makes hard to guarantee.

VAON's Solution

Built a real-time detection and tracking pipeline on a fixed camera, assigning an ID to each individual and updating the running count live on the frame.

Split counting into two scenarios with two different confidence levels, rather than reporting one blended number: gate-crossing counting (line-crossing, pigs moving past a fixed point) for high accuracy; in-pen counting in a crowded scene used as a cross-check and anomaly-alert signal, not an absolute count.

Chose this approach instead of forcing one model to hit high accuracy everywhere: in livestock computer vision, occlusion in a crowd is a physical limit of a single camera, not an algorithm defect. Separating the scenarios lets each be evaluated by what it can actually deliver.

Verified directly on demo footage: tracking stays stable in a sparse pen (7 individuals, little occlusion) and still functions in a crowded pen (24 individuals), with observed ID reassignment when an individual reappears after occlusion. That is real evidence for assessing the limit honestly rather than guessing.

Identified what gate-crossing counting needs before production use: a labeled pig-image dataset matching the actual farm's conditions (camera angle, lighting, breed) to train a model with a committable accuracy figure. This step has not been done yet, since the PoC proves technical feasibility and is not tied to a specific farm.

Stated scope, honestly. Four limits as they stand at this PoC: in-pen counting in a crowded scene is a monitoring aid, not an exact figure, because occlusion can give a reappearing animal a new ID; no farm-specific training dataset exists yet, and a committable accuracy for a real farm requires labelled images matching that farm's camera, lighting and breed; real-world farm noise (dust, high humidity, uneven night lighting) still needs validation beyond the demo environment; and the PoC scope is detection and counting only, so weight estimation, abnormal-temperature detection and behaviour analysis need different cameras and data.

Value Delivered

Gate-crossing: 95-98% accuracy, reliable enough for an official figure

For pigs moving past a fixed point (a gate or corridor), the system reaches 95-98% accuracy, reliable enough to serve as a farm's official reconciliation figure, on a validated line-crossing architecture.

Real-time tracking in a crowded pen, for herd-deviation alerts

The demo shows the system detecting and ID-tracking more than 20 individuals simultaneously in a crowded pen, updating the count live on the frame. The real value of this scenario is catching a deviation from the previous count early, not replacing the official figure.

No change to existing camera infrastructure

The pipeline runs on a fixed overhead camera angle, the installation style already common on farms today, so no specialised camera or pen layout change is needed to run the PoC.

Technology Stack

Object Detection & Tracking (PyTorch)
Object Detection & Tracking (PyTorch)
OpenCV
OpenCV
Python
Python
FastAPI
FastAPI