Computer vision answers · Retail

How do I count products on store shelves with computer vision?

Without walking every aisle with a clipboard.

Short answer

Train an object detection model to find each product on the shelf with Roboflow for free, then count the detections per class. Label each product as its own class, and add a class for empty facings, so you get stock and gaps for every shelf in one pass. Box every facing one by one, even where packs touch, and split wide shelf photos into tiles so small products far from the camera still get found.

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
Shelf photos and a detection model trained on your products
What you get
A count per product, with empty facings marked on every shelf
Image sources
Phone photos, fixed shelf cameras and recorded video
Runs on
Cloud API, or an edge device or server running Docker
AI system analyzing a retail shelf, showing bounding boxes around cola cans, water bottles, and empty spaces, with an inventory summary dashboard.

How to build shelf product counting, step by step

Six steps from a phone photo of a shelf to a count for every product.

  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 shelf photos, start training, build the Workflow and run the model from a prompt, at no extra cost beyond your Roboflow plan.

  2. Photograph shelves the way you will check them

    Take shelf photos from the same angle, distance and lighting you will use in production, whether that is a phone held at the aisle or a fixed shelf camera. Include full, half-empty and messy shelves so the model sees what real aisles look like.

  3. Label every facing, with one class per product

    Draw a box around every product facing and give each product its own class, plus an empty class for gaps on the shelf. Roboflow Annotate can pre-label photos with SAM 3, so you correct boxes instead of drawing each one.

  4. Train a detection model for small, crowded products

    Train an object detection model such as RF-DETR on your labeled shelf photos with Roboflow Train, and test it on aisles it has not seen.

  5. Count the products on each shelf photo

    Run the model on a shelf photo and count the detections in each class. The empty class tells you how many facings need restocking.

    Python
    import supervision as sv
    from collections import Counter
    from inference import get_model
    
    model = get_model("your-project/1")
    
    result = model.infer("aisle_04.jpg", confidence=0.4)[0]
    detections = sv.Detections.from_inference(result)
    
    print(Counter(detections.data["class_name"]))
    # Counter({'cola_330ml': 14, 'water_500ml': 9, 'empty': 3})

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

  6. Run every aisle and track stock over time

    Build a Workflow that splits wide shelf photos into tiles with the Image Slicer block, runs the model on each tile, and joins the results with Detections Stitch. Run it on shelf cameras or batches of photos with Roboflow Deploy and record the counts per shelf to see stock change over time.

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.