Computer vision answers · Manufacturing

How do I group detected parts into one larger object with computer vision?

So every part is counted against the right assembly.

Short answer

Train one detection model with Roboflow for free that finds both the larger object and its parts, then assign each part to the object whose box contains the part's center. You get each object with its own list of parts, ready to check or count. Label the larger object as its own class, so the model finds it directly instead of you guessing its outline from where the parts sit.

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 labeled with a class for the object and one for each part
What you get
Each object with its own list and count of parts
Image sources
Line cameras, phone photos and recorded video
Runs on
Cloud API, or an edge device or server running Docker
Two circuit boards with object detection annotations, one complete and the other showing a missing chip.

How to build part grouping, step by step

Six steps from labeled images to every object with its own list of parts.

  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. Label the larger object and each part as separate classes

    Draw a box around each whole object, such as a circuit board, and a box around every part on it, such as each chip and connector, with one class per part type. Roboflow Annotate can pre-label images with SAM 3, so you correct boxes instead of drawing each one.

  3. Train one detection model for the object and its parts

    Train an object detection model such as RF-DETR on your labeled images with Roboflow Train. One model that finds both the object and its parts keeps every box in the same image coordinates.

  4. Assign each part to the object that contains it

    Run the model, split the detections into objects and parts, and give each part to the object whose box contains the part's center point. Parts that touch two objects go to the one they actually sit on.

    Python
    import supervision as sv
    from inference import get_model
    
    model = get_model("your-project/1")
    result = model.infer("line.jpg", confidence=0.4)[0]
    detections = sv.Detections.from_inference(result)
    
    boards = detections[detections.data["class_name"] == "board"]
    parts = detections[detections.data["class_name"] != "board"]
    centers = parts.get_anchors_coordinates(sv.Position.CENTER)
    
    for i, (x1, y1, x2, y2) in enumerate(boards.xyxy):
        inside = (centers[:, 0] >= x1) & (centers[:, 0] <= x2) & (centers[:, 1] >= y1) & (centers[:, 1] <= y2)
        print(f"board {i}:", parts.data["class_name"][inside].tolist())
    # board 0: ['chip', 'chip', 'connector']
    # board 1: ['chip', 'connector']

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

  5. Build the grouping into a Workflow

    In a Workflow, the Overlap Filter block set to Center Overlap keeps only the parts that sit inside an object of your object class and drops loose ones. When there is no class for the whole object, the Detections Merge block draws one box around a set of detections. Run the Workflow with Roboflow Deploy in the cloud or on an edge device.

  6. Check each object against its expected parts

    Compare each object's list of parts to what it should have, such as four chips and one connector per board, and flag any object with a part missing or extra. Record the result per object, not per image, so one bad board does not hide behind a good one.

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.