Computer vision answers · Video Analytics

How do I get a running total for a whole video or shift with computer vision, not just a count of what’s in the current frame?

Every item that passes, from the start of the shift to the end.

Short answer

Train a detection model with Roboflow for free, track each object across frames so it keeps the same ID, and count it once as it crosses a line. The line's count keeps adding up for the whole video or shift, instead of resetting with every frame. Put the line where every object passes exactly once and moves cleanly across it, away from where items pile up or stop, so nothing crosses twice.

Roboflow agent · free to start

Skip the setup. Describe your images.

Describe your images and what you need to find. The agent sets up labeling, training and deployment with you.

Key facts

What you need
A fixed camera, a detection model and object tracking
What you get
One total per shift, plus counts in and out by class
Image sources
Live camera streams and recorded video
Runs on
Cloud API, or an edge device or server running Docker
AI vision system tracking and counting cartons on a factory conveyor belt, showing green bounding boxes, a yellow count line, and a live display totaling 1284 cartons.

How to build a running total, step by step

Six steps from a camera on the line to one total for every shift.

  1. Connect Roboflow to your coding agent, ChatGPT or Codex

    Add the Roboflow MCP server to Claude, Cursor or Gemini CLI, or install the Roboflow plugin in ChatGPT or Codex. Your assistant can then upload and auto-label video frames, start training, build the Workflow and run the model from a prompt, at no extra cost beyond your Roboflow plan.

  2. Record video of a full shift

    Mount a fixed camera where everything you want to count passes through, and record both busy and quiet periods, in the lighting you will run in.

  3. Label your objects and train a detection model

    Draw a box around each object in frames from your video, with one class per type, using Roboflow Annotate and its SAM 3 pre-labeling. Then train an object detection model such as RF-DETR with Roboflow Train.

  4. Track each object so it is counted once

    A count of what is in the frame counts every object again on every frame. Object tracking gives each object an ID that lasts from frame to frame, so the same box on a conveyor is recognized as one box all the way across the view.

  5. Count every object that crosses a line

    Draw a line across the path your objects take, track them through the whole video, and add one to the total each time a tracked object crosses the line.

    Python
    import supervision as sv
    from inference import get_model
    from trackers import ByteTrackTracker
    
    model = get_model("your-project/1")
    tracker = ByteTrackTracker()
    line = sv.LineZone(start=sv.Point(640, 0), end=sv.Point(640, 720))
    
    for frame in sv.get_video_frames_generator("shift_0600.mp4"):
        detections = sv.Detections.from_inference(model.infer(frame, confidence=0.4)[0])
        line.trigger(tracker.update(detections))
    
    print("total in:", line.in_count, "total out:", line.out_count)
    # total in: 1284 total out: 0

    Rather not write code? Ask the Roboflow agent to set this up for you

  6. Total it up by shift in a Workflow

    In a Workflow, add Byte Tracker and the Line Counter block to keep a running count, then the Data Aggregator block with an 8 hour interval, which gives one total per shift and starts again. Run it on your camera stream with Roboflow Deploy.

Why 2 million engineers build on Roboflow

  • Label faster

    Auto-label with SAM 3 or your own model, then fix the misses instead of drawing every box.

  • RF-DETR

    Roboflow’s open-source real-time detection model, built for accuracy (opens in a new tab) on small objects.

  • Logic built in

    Counting, zones, tracking and alerts are ready-made Workflow blocks, so there is less code to write.

  • Your model, your weights

    Use your trained weights on every plan, including free, through the open-source Inference package.

  • Run it anywhere

    Self-host on a workstation, Docker, an on-prem GPU or an edge device, or call the cloud API.