Computer vision answers · Manufacturing

How do I build a pass/fail check that compares an expected count?

Without an inspector counting every part by eye.

Short answer

Train an object detection model to find each part with Roboflow for free, then count the detections for each class and compare each count with the number you expect. Return PASS when every count matches and FAIL when a part is missing or there is one too many. Compare counts per class, not one total, so a missing screw and an extra clip can never cancel out into a false PASS.

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
Images of each item and a detection model trained on its parts
What you get
A PASS or FAIL per image, with the count found for each part
Image sources
Line cameras, IP and RTSP cameras, phone photos and saved images
Runs on
Cloud API, or an edge device or server running Docker
An object detection system identifies 3 screws and 2 clips on a metal plate, showing a count check failure for screws (3 of 4).

How to build a pass/fail count check, step by step

Six steps from images of your product to a PASS or FAIL for every item.

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

  2. Photograph good and faulty items the way the line will see them

    Capture images from the camera position, distance and lighting you will use in production. Include items with a part missing and items with one part too many, so the model learns from every case the check has to judge.

  3. Label every part, with one class per part type

    Draw one tight box around every part and give each part type its own class, such as screw, clip or bracket. Roboflow Annotate can pre-label images with SAM 3, so you correct boxes instead of drawing each one.

  4. Train a detection model

    Train an object detection model such as RF-DETR on your labeled images with Roboflow Train. A count check is only as good as the model, so test it on images it has not seen before you trust its verdicts.

  5. Compare each part's count with the count you expect

    Run the model, count the detections for each class and compare every count with the number the item should have. The item passes only when every part type matches its expected count.

    Python
    import supervision as sv
    from collections import Counter
    from inference import get_model
    
    model = get_model("your-project/1")
    expected = {"screw": 4, "clip": 2}
    
    result = model.infer("part_001.jpg", confidence=0.5)[0]
    detections = sv.Detections.from_inference(result)
    counts = Counter(detections.data["class_name"])
    
    passed = all(counts[name] == n for name, n in expected.items())
    print(dict(counts), "PASS" if passed else "FAIL")
    # {'screw': 3, 'clip': 2} FAIL

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

  6. Build the check into a Workflow and deploy it

    Build a Workflow with your model, a Property Definition block that counts the detections and an Expression block that compares the count with an expected-count input and returns PASS or FAIL. Passing the expected count as an input lets one Workflow check several products. Run it on images or a camera stream with Roboflow Deploy in the cloud or on an edge device.

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.