blog · computer vision for biology
Finding every bee on a comb
Segmenting, orienting and tracking honeybees in near-infrared images from inside a hive, where they crowd, overlap and crawl over each other. One network draws four maps; a little geometry turns them into a position and heading for every bee. The geometry runs in your browser below.
Why count bees one by one
A honeybee colony shows stress in its behaviour long before it shows on an inspection: how active the workers are, how they tend the brood, how often they meet and feed each other. To measure that, you need to know where each bee is and which way it faces, frame after frame, for weeks, without opening the hive.
That is what the robotic observation hives of our partners at the University of Graz do. A camera on a robotic gantry moves behind the glass of a double comb and images it in near-infrared light, between 750 and 850 nm, which the bees cannot see. The result is hours of footage like the frame below, with up to a hundred bees in view, touching, overlapping, half hidden in cells.
Boxes are the usual way to detect objects, and they fit bees badly. Two bees lying side by side at an angle share most of their boxes. A box also does not say which end of the bee is the head, and for biology the heading is not a detail: feeding, waggle dances and the bees attending the queen are all defined by where an individual faces.
Four maps instead of boxes
So we let a network draw maps instead. An encoder–decoder network (an "hourglass" with skip connections) takes one grayscale image and predicts, for every pixel, four values:
- thorax: a filled ellipse over the middle of the body,
- abdomen and head: soft gradients towards the two ends of the body, and
- anchor: a small disk at the centre of each bee.
The first three maps are the body-part segmentation. The fourth is what makes detection easy: anchors are small and round, so they stay apart even when the bodies around them overlap. The network was trained on 876 hive images in which every visible bee was annotated as an oriented ellipse, about 33 000 bees in total. The four targets above were drawn from those ellipses automatically.
Turning the maps into bees takes three cheap steps, which you can step through on a real frame:
one frame · from pixels to poses in your browser
– bees found · click a bee for its scoresStep 3 is the instance segmentation: threshold the anchor map and every connected blob is one bee. Raise the anchor threshold and bees start to disappear; lower it far enough and neighbouring anchors merge, so two bees become one. That merging is the method's main weakness in the densest clusters.
Step 4 finds the body axis. The three body-part maps together form one elongated blob per bee, and an ellipse fitted to it gives the axis. An ellipse is symmetric, though: it cannot tell the head from the abdomen.
Step 5 decides that. For each bee there are just two hypotheses, head at one end of the axis or at the other. Each places a small Gaussian at the expected abdomen and head positions, half a body length (35 px) from the centre, and scores itself by how much abdomen and head the network sees under them:
The higher score wins. (The paper's score also has a thorax term, but the thorax sits at the centre under both hypotheses, so it cannot change the decision.) All bees and both hypotheses are scored at once; on a GPU this is a single batched operation, and here your browser does it for every bee in a few milliseconds.
On a held-out acquisition of 121 images with 4 247 annotated bees, recorded after all training images.
How well it works
We evaluated on images recorded after the whole training set, so the network had never seen those days in the hive. The heatmaps are almost exact at the pixel level, and 96.4 % of the detected bees are real bees. The recall of 85.0 % is lower, and the misses are where you would expect them: in the tightest clusters, where anchor blobs of packed bees merge into one.
The heading is where the approach differs most from box detectors. The closest comparable detector, evaluated on images from the same hives, needs a second network to estimate orientation and reaches a mean error of 19.2°; ours reads it from the same heatmaps at 4.6°. And because the masks are a by-product, every bee comes with its body parts segmented too.
The full pipeline takes about 0.12 s per frame on an older GTX 1070 Ti and runs at about 12 frames per second on an NVIDIA Jetson Orin AGX.
From detections to tracks
Precise single-frame detections make tracking simple. From one frame to the next, every known bee is matched to the new detection that is closest and points the same way, cheapest pairs first. A detection with no match becomes a new bee only after it has shown up in three frames, which filters out flickers; a bee that disappears is kept for a few frames, so that a moment of occlusion does not cost it its identity. If a single frame was unsure which end is the head, the bee keeps the heading it had.
six seconds in the hive · detected and tracked in your browser
Sixty frames from the worker camera of an AROBA observation hive, 3 July 2024, at ten frames per second. The heatmaps were computed offline at half resolution; detection, heading and tracking run in your browser when you load the clip.
Where it is used
The detector is the component other parts of our hive work build on. It has been used to monitor colony populations, to plan the paths of robots that interact with the bees, to forecast when parts of the comb will be hidden by bees, and to map combs for brood surveillance. The next step we are working towards is recognising individuals: the camera already resolves the vein pattern of the wings, which we hope can serve as a fingerprint.
The dataset, the annotations, the trained model and the evaluation code are open, under CC BY 4.0.
Read more
- Z. Rozsypálek, T. Rouček, J. Ulrich, L. Fedotoff, M. Stefanec, T. Schmickl, F. Arvin, T. Krajník: Anatomical segmentation and pose estimation of honeybees in near infrared comb imagery. IEEE MetroAgriFor 2026, Potsdam.
- Dataset, annotations, model and code: doi.org/10.5281/zenodo.22759407 (CC BY 4.0).
- An open-source high-precision hive for long-term honeybee observation and research. Biology Open, 2026. The hive.
- Autonomous tracking of honey bee behaviors over long-term periods with cooperating robots. Science Robotics, 2024. The robots that observe the colony.
- Video: detection and tracking of bee workers on YouTube.