Object Counting in Computer Vision: How It Works in Production

Object counting in production: when to use detection, tracking or density estimation, and why count MAE on real footage matters more than benchmark mAP.

Object Counting in Computer Vision: How It Works in Production
Written by TechnoLynx Published on 11 Jul 2026

Object counting in computer vision means turning an image or a video stream into a number: parts on a tray, vehicles past a gantry, packs on a shelf. The common approaches count the boxes a detector returns, track objects and count them as they cross a line or zone, or estimate a density map and add it up. In the studies cited here, count accuracy is measured as mean absolute error or as a percentage of manually counted ground truth. A counter that looks right on sample images and drifts on the line is one instance of the wider pattern of why off-the-shelf CV models fail in production.

How Does Object Counting Work, and What Does It Mean in Practice?

In practice, object counting is a separate task from object detection, even when a detector does most of the work. Lempitsky and Zisserman (NIPS 2010) describe three families: counting by detection, counting by regression, and counting by estimating a density whose integral gives the count.

Counting by Detection

Counting by detection runs an object detector that localises each instance and counts the detected objects. Once every instance is found, the counting is trivial, but detection is far from solved for overlapping instances. A 2026 arXiv study on counting machine parts describes this naive approach as somewhat effective in low-density scenes, and says it has trouble generalising to images with many objects. In the Ultralytics counting solution, the confidence threshold defaults to 0.25, and lowering it lets more objects through at the cost of false positives. A max_det cap of 300 limits how many detections a frame keeps in dense scenes. If a scene holds more objects than the cap, the count cannot reach the true number at that setting.

Counting by Tracking Across a Line or Zone

On video, one method is to detect, track and count crossings. You define a line with two points, or a polygon with three or more. The counter follows each object across frames and adds to IN or OUT tallies when a tracked object crosses the line or passes through the region. The tracker matters because a video is not a stack of independent photos. In our own write-up of temporal pipelines, a part gets counted three times as it drifts across the frame, then disappears for four frames when a robot arm hides it. An IOU tracker relies heavily on how accurately objects are detected, so the detector still needs proper training. Our page on multiple object tracking in production covers how trackers lose and reassign identities.

Counting by Density Estimation and Regression

Density estimation predicts a map in which the sum over any region equals the number of objects in that region. It is trained from a single dot on each object rather than from boxes. Because it never detects objects explicitly, it sidesteps the difficulty of heavy occlusion and low resolution while keeping some spatial information. Pure regression goes one step further and maps global image features straight to a number. That throws away location, and it needs a large number of counted training images.

When Should I Use Detection-Based Counting Versus Density Estimation Versus Tracking-Based Counting?

Choose by scene density, by whether objects move past a fixed point, and by whether you need anything besides the number.

Approach Fits Breaks when What you get besides the count
Counting by detection Sparse, separated objects in still images or single frames Objects pack closely or overlap, and box suppression merges or splits them A box per object, which is easy to audit
Detection plus tracking, line or zone crossing Objects moving past a fixed point: a conveyor, a road, a doorway Duplicate boxes and identity switches inflate the tally, and occlusion breaks tracks Directional IN/OUT tallies and trajectories
Density estimation Dense, overlapping or low-resolution scenes Small counts that must be exact, where the margin of error has to be low A density map with approximate locations and no identities
Regression to a count Plenty of counted training images and no need for location Training data is limited Nothing beyond the number

The table gives you a starting point. It does not settle the choice. The machine-part study argues that density methods suit large crowds better than precise part counts. Yet in the same study, a fine-tuned FamNet few-shot counter reached an MAE below 2 on washers, against 3.79 for a fine-tuned Mask R-CNN and 29.01 for classical image processing. We read this as a sign that fit to the domain decides more than the method family does, and the only way to know is to measure on your own parts.

Why Does a Detector That Benchmarks Well Still Produce Inaccurate Counts in Production?

A good benchmark score means the detector does well on the benchmark’s data at the benchmark’s thresholds. A count depends on the production data at one operating threshold. One object detection model from our deployment work scored 94% mAP on its evaluation set, passed integration testing and gave a clean demo. Four weeks into production, its false-positive rate was three times higher than in evaluation. In a counter, every false positive that survives is one extra in the tally.

In the 2026 machine-part study, a Mask R-CNN’s MAE fell from 26.1963 to 3.7889 after fine-tuning. The authors attribute the gap to COCO 2017 being heavily out of distribution: it has large objects such as people and animals, and less clutter than their washer images. The cameras matter too. A comparative vehicle-counting study (arXiv 2007.16198) put its below-optimal detection results down to poor camera quality, camera views shaken by wind and fog or mist on the lens. In the same study, EfficientDet paired with SORT or KIOU failed in daylight, night-time and rain.

Off-the-shelf models that work in demos fail in production at the edge cases, lighting conditions and throughput requirements of real deployments. Counting makes the break easier to see, because every error ends up in a number someone reports.

How Do Occlusion and Dense Packing Degrade Counting Accuracy, and How Is That Measured?

Occlusion and dense packing degrade counts in both directions, so measure them as a signed error broken down by scene condition, not as one average.

The SKU-110K benchmark (CVPR 2019) consists of retail shelf images averaging 147.4 objects each. On it, RetinaNet often returned boxes that partly covered several items, or reported adjacent parts of one item as separate objects. Non-maximum suppression did not separate overlapping detections or suppress partial ones well. The gap in counting accuracy between methods was larger than the gap in detection accuracy, and the authors attribute part of it to greedy NMS. Even their best method’s results remain far from perfect on such scenes. A density-map study (arXiv 1705.10118) states the general rule: detection-based counting gets worse as scenes become more crowded and objects get smaller.

Occlusion pushed counts both down and up in the studies below:

  • Undercount: in the vehicle study, larger vehicles often hid cars close to the camera.
  • Overcount: the same study found that occlusion and low visibility caused identity switches and repeat detections, which inflated vehicle counts. Counts above 100% of ground truth usually meant both the detector and the tracker were at fault.
  • Density undercount: density estimation can still miss objects that are only partly visible. One model predicted zero density on a roof that hid all but the heads of the people below it.

The machine-part authors found occlusion caused their model’s major remaining performance drop. They tried splitting images by depth and counting each layer separately. To measure this yourself, label each validation clip or image by density and occlusion level, then report count error per level. One overall MAE averages a calm shift and a jammed conveyor into a figure that describes neither.

What Does Count Error Rate Look Like as a Production Metric Versus Benchmark Accuracy?

Count error is measured per image or per counting interval against a human count. Mean absolute error is the average absolute difference between the predicted count and the true count per image. The machine-part and SKU-110K papers report it alongside root mean squared error. RMSE weights large misses more heavily, so a gap between RMSE and MAE points to occasional bad frames rather than a steady bias. The vehicle-counting study reports automatic counts as a percentage of ground truth, and the VLMCountBench study (2025) uses relative error, meaning how far a prediction falls from the truth in proportion to it.

mAP summarises detection quality across thresholds and recall levels, and our metrics guide has IoU and mAP explained in full. The trouble for counting is that a counter runs at one threshold, and duplicates, misses and NMS behaviour at that one point decide the number.

MAE ignores where in the image the counts were made. Within one image, a false positive and a missed object cancel to a count error of zero. The TRANCOS vehicle-counting paper (IbPRIA 2015) found that a HOG-based detector had the best MAE partly because false positives padded its count. It proposed the Grid Average Mean absolute Error (GAME), which splits the image into cells and penalises counts placed in the wrong location. With no subdivision, GAME(0) equals MAE. Where an audit needs to know which items were counted and where, check location as well as the total.

How Do I Validate an Object-Counting Model Against Representative Production Footage Before Deployment?

Validation means comparing the full pipeline’s counts against human counts on footage that covers the conditions the line will actually see. The vehicle-counting study validated its counts this way. It compared every detector and tracker combination against manual counts of more than 9 hours of traffic video from the Louisiana Department of Transportation and Development.

  1. Sample the real conditions. Use each camera, shift, lighting state, product variant and failure condition you expect (dirty lens, vibration, jams), and not just the clean clips that made the demo look good.
  2. Count by hand. Put one dot per object, or record a tally per interval for line crossings. Dots also give you density-map training data later if you need it.
  3. Stratify. Label each sample by density and occlusion level so that error can be reported per condition.
  4. Run the whole pipeline at production settings. Use the deployed confidence threshold, detection cap, tracker and frame rate, because each of these changes the count.
  5. Report error per stratum. Use MAE, RMSE and count as a percentage of ground truth; in the vehicle study, counts above 100% meant both detector and tracker were at fault.
  6. Check location on a sample. Use GAME or a manual review of frames to catch errors that cancel out.
  7. Fine-tune, aggregate and re-measure. Domain fine-tuning cut MAE sharply in the machine-part study, and averaging predictions reduced it again, from 2.60 to 1.96.
  8. Write down the expected performance per environment. The output is a stated count error that the people using the numbers can plan around.

TechnoLynx’s Computer Vision R&D team runs this validation against manual counts on representative footage. An outside assessment is most useful when nobody owns ground truth or when the counts feed reporting that others rely on. For the artefacts that keep such a model running after launch, see industrial CV inspection production reliability.

What Throughput Trade-Offs Come with Each Counting Approach on an Industrial Line?

Counting by detection pays the detector’s full cost on every decoded video frame. Tracking adds an association step that follows each object across frames. Fully convolutional networks that predict the whole image at once are especially fast because they reuse computation, and reduced-resolution density maps speed prediction up while keeping counting accuracy. The original density-learning method added almost no time beyond feature extraction at test time. The trade-off is location: reduced-resolution maps count well but place individual objects poorly. The end-to-end cost of decode, inference and tracking is covered in our breakdown of the real-time detection pipeline and what throughput costs.

Are Free Counting Apps or General Vision-Language Models Accurate Enough for Industrial Counts?

With a custom template, a photo-counting app counted small, well-spaced seeds quickly and accurately. In VLMCountBench, general vision-language models did not count exactly and reliably, even on simple shapes, once shape types were mixed. A study tested the CountThings From Photos app on sagebrush seeds. A custom template explained 83% of the variation in actual seed counts, rising to 95% when the model was forced through the origin, and took 10% of the time of counting by hand. The same authors linked inaccurate counts to low photo quality. They recommended clean, well-spaced seeds and sharp images. Explained variance is not count error, and a line rarely offers well-spaced objects.

General VLMs struggle with counting. VLMCountBench (2025) tested them on simple geometric shapes. Qwen2.5 72B’s exact-count accuracy fell from 0.60 to 0.45 as more shape types were mixed in, and Gemini 2.5 Flash fell from 0.58 to 0.30, with relative error rising from 0.04 to 0.13. The failures came when two or more shape types were mixed, even with small numbers of objects.

How Should You Think About Object Counting in Practice?

Treat an object counter as a measuring instrument. It has a stated error, the error holds for each environment you measured it in, and it has to be measured again when the environment changes. The method choice (detection, tracking or density) follows from scene density and motion. The benchmark score of the detector inside it tells you little about the count. Once the counter is live, the open question is how long its error figure stays true. Objects unlike the training data, or a shaken or fogged camera, shift the conditions you validated against. Plan the next manual-count check when you deploy, not after the totals start to look wrong.