Counting with cameras: from frame to a number you can trust

A camera can count boxes on a belt, customers at a door and cars at a barrier. Getting a number is easy – getting the right number while storing no more about people than necessary is the hard part. Here are the three ways to build it, the sources of error and a small example…

Last checked:

Step by stepWhat makes the number wrong?
  1. Objects hiding each other
  2. Too few pixels
  3. Light and motion blur
  4. Tracking loses the object
  5. The model does not know the thing

Three kinds of counting

Before choosing equipment, decide which of three tasks you have. They look alike but need different set-ups.

  • Flow across a line. Something crosses an imaginary line: goods on a conveyor, people in an entrance, cars at a gate. The result is “in” and “out”. The model has to follow each object across several frames so it is counted once – this is called tracking.
  • Occupancy in a zone. How many people are in the checkout queue right now, how many spaces are taken? You count what is inside an area at a moment. Tracking helps but is not always needed.
  • Counting in a still image. How many pallets are on the rack, how many sacks are in the store? One photo at a time – from a fixed camera or a phone – and one number per photo.

The first two run on video and are best processed close to the camera. The third suits a cloud service well, because only a few images are sent.

Three ways to build it

Camera analytics, edge box or cloud

RouteWhat it isGood forWeak at
The camera’s own analyticsAnalytics bundled with the camera, e.g. line counting of people and vehiclesQuick start, no extra computer, the image never leaves the cameraOnly the object types the maker trained; hard to adapt
Edge box with an open modelA small computer next to the camera runs e.g. YOLO and forwards only numbersYour own product types, many cameras, full control of dataNeeds set-up, upkeep and often a commercial licence
Cloud APIStill images go to Google, AWS or Azure, which return objectsFew images, quick prototype, no hardwarePrice per image, images leave the building, not for continuous video
Pros and cons of the three routes to counting

Built-in analytics is often enough for people and cars. Axis, for example, says its Object Analytics comes preinstalled on compatible cameras at no extra cost and counts humans and vehicles crossing a line directly in the camera. If you need to count your own goods – a specific crate, bottle or sack – you need a model trained on them. Cloud and licence prices are on the vision tools page.

What makes the number wrong?

A count is only as good as the image. The same error sources come up again and again:

  1. Objects hiding each other. Two people walking side by side look like one from the front. A camera pointing straight down solves most of it.
  2. Too few pixels. If the object is small in the frame, the model guesses. Our own segmentation measurements show the same: large surfaces such as floors are found precisely, narrow things such as window frames poorly.
  3. Light and motion blur. Backlight in a gateway and fast objects in dim light give blurred frames. A shorter shutter time and more light help more than a bigger model.
  4. Tracking loses the object. Each track ID is counted once. If tracking loses a person behind a pillar and gives her a new ID, she is counted twice. Put the line where the view is clear and at right angles to the direction of travel. In our research pipeline for speed, tracking is its own step after detection – precisely because that is where many errors arise.
  5. The model does not know the thing. Standard models are trained on everyday objects such as people, cars and bicycles. A plastic crate with your logo is not among them.

Vision-language models that can answer questions about a photo – such as moondream2 and Qwen3-VL – are on our research list for tagging images in bulk. Our judgement: they are fine for sorting images, but a real detector is the safe choice when an exact count matters.

Count without storing faces

The best data protection is not having the data. Number plates, locations and faces together are sensitive under GDPR, which is why we build counting like this:

  • The frame is processed in memory and forgotten. Only the number – time, in and out – is written down. No video is stored.
  • The camera hangs overhead. Faces are not in focus and nobody can be recognised on a still.
  • Low resolution where it is enough. A counter does not need 4K.
  • Blurring as a safety net. If images must be kept for debugging, people can be blurred automatically before storage.

Legally this is not a free pass. Under the Danish Act on TV Surveillance, TV surveillance is continuous or regular monitoring of persons by an automatic camera, and a people counter can fall under it. The duty to put up signs does not apply to monitoring without recording of your own entrances, façades and fences (section 3(2)), but the GDPR duty to inform still applies. If the camera hangs in a workplace, employees must be informed. See the cameras and GDPR page.

A minimal example with an open model

The code below counts people crossing a vertical line and writes only numbers to a CSV file – one row a minute. It uses Ultralytics’ ready-made ObjectCounter and the smallest YOLO26 model, which downloads automatically the first time.

# Counts people crossing a line. Stores numbers only, never images.
import csv
import time

import cv2
from ultralytics import solutions

SOURCE = "test.mp4"  # or "rtsp://<CAMERA-IP>/stream1"
LINE = [(320, 0), (320, 720)]  # two points in pixels = a counting line

counter = solutions.ObjectCounter(
    model="yolo26n.pt",  # small model, runs on CPU
    region=LINE,
    classes=[0],  # COCO class 0 = person
    show=False,
    verbose=False,
)

cap = cv2.VideoCapture(SOURCE)
with open("counts.csv", "a", newline="") as f:
    log = csv.writer(f)
    last = time.time()
    while cap.isOpened():
        ok, frame = cap.read()
        if not ok:
            break
        counter(frame)  # the frame is used and forgotten
        if time.time() - last >= 60:
            log.writerow([time.strftime("%H:%M"),
                          counter.in_count, counter.out_count])
            last = time.time()
    log.writerow([time.strftime("%H:%M"),
                  counter.in_count, counter.out_count])
cap.release()
print("in:", counter.in_count, "out:", counter.out_count)

Install with pip install ultralytics. We ran exactly this code on 20.11.2026 with ultralytics 8.4.216 on an ordinary computer without a graphics card. The test video was synthetic: Ultralytics’ own sample picture of a bus with pedestrians sliding past the line in six seconds. The result was in: 0 out: 3 – three people crossed the line, and the fourth, who is only half in the picture, was not counted. That is a functional test of the code, not an accuracy measurement. Ultralytics’ official YOLO guides have been part of our toolkit since 14.11.2026.

Two things before this becomes more than a test. First, the licence: Ultralytics publishes YOLO under AGPL-3.0. According to the company’s licence page, use in an internal business tool, a commercial product or embedded in a camera requires an Enterprise licence unless you open-source your whole project. The price is only given on request. Second: no model of ours runs in production anywhere today – the example shows how it is done, not that we operate it.

From numbers to decisions: calibrate against a manual count

Test the camera against reality before you use the number. The simplest method: count by hand for an hour with a clicker and compare.

Worked example: deviation from a manual count

PeriodManual countCamera countDeviation
10:00–10:204846−4.2 %
10:20–10:407166−7.0 %
10:40–11:0039390.0 %
Whole hour158151−4.4 %
Made-up figures for one entrance over one hour. Formula: deviation = (camera − manual) ÷ manual × 100

Look hardest at the busiest interval. People walk close together then, and that is where a camera typically undercounts. If the deviation is too large, move the camera or the line before trying a bigger model. Repeat the test when the season and the light change.

Questions about counting with cameras

Can an AI camera count people?

Yes. Many recent surveillance cameras have built-in line counting of people, and open models can do the same on a small computer. Accuracy depends mostly on placement and light – test against a manual count.

How accurate is camera-based people counting?

It can only be measured at your own entrance. In dense traffic with a front-facing camera, systems typically undercount because people hide each other. An overhead camera is the most important fix.

Do we need signs if the camera only counts?

It depends on where it hangs and whether it records. Monitoring without recording of your own entrances and façades is exempt from the sign duty, but GDPR’s information duty still applies, and in a workplace employees must be informed.

Can AI count goods on a conveyor?

Yes, and it is often easier than people, because light and angle are fixed. If the item needs a model trained on your own products, images must be collected and labelled first.

Sources

Last reviewed: 2026-12-03

Fixed price, no commitment

Get a concrete answer

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?