{"slug": "dimensional-defect-inspection-with-vision-ai", "title": "Dimensional Defect Inspection with Vision AI", "summary": "Roboflow released a guide on using Vision AI to automatically inspect manufactured parts for dimensional defects, such as incorrect size, spacing, or alignment. The workflow uses Gemini to detect features and a Python block to measure distances, returning a pass or fail against tolerances.", "body_md": "*Dimensional defects are parts that fall outside their intended size, spacing, position, or alignment tolerances, invisible to the eye but enough to stop a part from fitting or working. You can catch them automatically in a Roboflow Workflow: Gemini detects the features, a small Python block measures the center-to-center distance, and it returns a pass or fail against your tolerance.*\n\nAt first glance, a manufactured product may look perfectly fine. There are no scratches, dents, or other visible defects, and everything appears to have been made correctly. However, even a small difference in size, spacing, or alignment can be enough to prevent the product from functioning as intended.\n\nThese types of issues are known as dimensional defects. Unlike surface defects, which affect a product's appearance, dimensional defects occur when a part's size, spacing, or alignment falls outside its intended specifications. Even small measurement errors can impact product quality, assembly, and performance.\n\nIn this guide, we will explore what dimensional defects are, look at some common examples, and build a Roboflow Workflow that uses computer vision to automatically inspect parts for dimensional defects.\n\n## What Are Dimensional Defects?\n\nA dimensional defect occurs when a manufactured part falls outside its intended dimensions or tolerances. Unlike surface defects, which affect a product's appearance, dimensional [defects](https://roboflow.com/ai/defect?ref=blog.roboflow.com) are related to a part's physical geometry, such as its size, spacing, position, or alignment.\n\nFor example, a part may be slightly too long, a hole may be drilled a few millimeters away from its intended position, or two components may be spaced farther apart than expected. While these differences can be small, they may prevent a product from fitting together correctly or functioning as intended.\n\nBecause of this, dimensional defect inspection plays an important role in manufacturing quality control, helping ensure that every part meets the required specifications before it reaches the customer.\n\n## Common Types of Dimensional Defects\n\nDimensional defects can appear in many different forms depending on the product being manufactured. Some of the most common examples include:\n\n**Incorrect dimensions:** A part is longer, shorter, wider, or taller than its intended size.**Hole position errors:** A hole is drilled slightly above, below, or beside its intended location.**Incorrect spacing:** The distance between two holes, connectors, or other features falls outside the acceptable tolerance.**Misalignment:** Components such as connectors, bottle caps, or other assembled parts are not positioned correctly.**Excessive gaps:** The gap between two parts is larger or smaller than expected, preventing a proper fit or seal.\n\nRather than manually inspecting every part, computer vision can automate much of this process by detecting the relevant features, measuring their dimensions or positions, and determining whether they fall within an acceptable tolerance. In the next section, we will build a Roboflow Workflow that performs this inspection automatically.\n\n## Build a Dimensional Defect Inspection Workflow\n\nNow that we've explored what dimensional defects are and why they matter, let's build a Roboflow Workflow that automatically inspects the spacing between two mounting holes on a steel bracket.\n\nAlthough this example focuses on measuring the distance between two holes, the same approach can be adapted to inspect many other dimensional features, including connector alignment, component spacing, hole position, gaps between assembled parts, or even the overall dimensions of a product.\n\nBefore getting started, it's important to understand one limitation of image-based measurements. Since our workflow measures distances directly from the image, every part should be captured under consistent conditions. Ideally, the camera should remain fixed with the same distance, angle, focal length, lighting, and image resolution throughout the inspection process. This ensures that measurements remain consistent from one image to the next.\n\nIn this tutorial, we'll compare measurements directly in pixels because every image is captured under identical conditions. If you're adapting this workflow for a real manufacturing application, begin by calibrating your camera using a known-good part or calibration target. This establishes the relationship between pixels and real-world units, allowing you to configure the expected dimensions and tolerances according to your product's specifications.\n\n### Step 1: Log into Roboflow\n\nStart by logging into your [Roboflow](https://roboflow.com/?ref=blog.roboflow.com) account. If you don't already have one, you can create a free account and access the Workflow editor from your dashboard.\n\n### Step 2: Create a Workflow\n\nFrom the Roboflow dashboard, navigate to **Workflows**, then click **Create Workflow**.The Input and Output blocks are added automatically, so we'll focus on building the inspection pipeline between them.\n\n### Step 3: Add a Google Gemini Block\n\nAdd a [Google Gemini](https://roboflow.com/model/google-gemini?ref=blog.roboflow.com) block to the workflow and connect it to the **inputs** block. We'll use Gemini to detect the features we want to measure. Set **Task Type** to **Unprompted Object Detection**, then add three classes to the **Classes** field: `mounting_bracket`\n\n, `left_hole`\n\n, and `right_hole`\n\n. Including the bracket itself alongside the two holes provides Gemini with additional context, making it easier to localize two small, similar-looking holes accurately, rather than guessing at their position in isolation. Expand **Additional Properties** and set **Model Version** to **Gemini 3.1 Pro**, then set **Thinking Level** to **low**, since this is a straightforward detection task that doesn't need deep reasoning.\n\nOnce configured, Gemini returns predictions for the overall mounting bracket as well as each detected mounting hole. In the next step, we'll use the VLM As Detector block to convert these predictions into standard object detections with bounding boxes that can be processed by the remaining workflow blocks.\n\n### Step 4: Add a VLM As Detector Block\n\nAdd a **VLM As Detector** block and connect it to the Google Gemini block. Since Gemini's raw output is **structured text rather than object detections**, this block converts the response into standard bounding box detections.\n\nSet **Model Type** to **google-gemini** and **Task Type** to **Unprompted Object Detection**.\n\nWith this in place, the workflow now has proper bounding box detections for `mounting_bracket`\n\n, `left_hole`\n\nand `right_hole`\n\nthat downstream blocks can actually measure against.\n\n### Step 5: Add a Custom Python Block\n\nNow add a **Custom Python Block**. This is where the actual dimensional inspection happens. Click the **Edit Code** button and add three inputs in the panel that opens up. Add a **predictions** input and set type as **object_detection_prediction**.** **Then add two more inputs, **expected_distance** and **tolerance**, both typed as float/integer. Add two outputs as well, **result** typed as string and **measured_distance** typed as float, since the block needs to report both the pass/fail verdict and the number it measured.\n\n``` python\nimport math\n\ndef run(self, predictions, expected_distance, tolerance):\n    # Get class names from the detections\n    class_names = predictions.data[\"class_name\"]\n\n    left_center = None\n    right_center = None\n\n    # Find the center of each detected hole\n    for box, class_name in zip(predictions.xyxy, class_names):\n        x_min, y_min, x_max, y_max = box\n\n        center_x = (x_min + x_max) / 2\n        center_y = (y_min + y_max) / 2\n\n        if class_name == \"left_hole\":\n            left_center = (center_x, center_y)\n\n        if class_name == \"right_hole\":\n            right_center = (center_x, center_y)\n\n    # Stop if either hole was not detected\n    if left_center is None or right_center is None:\n        return {\n            \"result\": \"ERROR\",\n        }\n\n    # Measure center-to-center distance\n    dx = right_center[0] - left_center[0]\n    dy = right_center[1] - left_center[1]\n    measured_distance = math.sqrt(dx**2 + dy** 2)\n\n    # Compare measurement to tolerance\n    if abs(measured_distance - expected_distance) <= tolerance:\n        result = \"PASS\"\n    else:\n        result = \"FAIL\"\n\n    return {\n        \"result\": result,\n        \"measured_distance\": measured_distance\n    }\n```\n\nThe script pulls the class name and bounding box for every detection, calculates the center point of whichever box is labeled `left_hole`\n\nand whichever is labeled `right_hole`\n\n, and if either one is missing it returns `ERROR`\n\nimmediately rather than trying to measure a distance that doesn't exist. Once both centers are found, it measures the straight-line distance between them with the standard distance formula, then checks whether that measurement falls within `tolerance`\n\nof `expected_distance`\n\n. For this walkthrough, set **expected_distance** to `700 pixels`\n\nand **tolerance** to `10 pixels`\n\n, which are placeholder values you'll want to swap out for your own bracket's real spec once you're inspecting actual parts.\n\nThis is the step that actually turns two bounding boxes into a pass/fail decision, and because it's plain Python, you can adapt the measurement logic to check spacing, alignment, or any other geometric relationship without touching the rest of the pipeline.\n\n### Step 6: Add a Bounding Box Visualization Block\n\nAdd a **Bounding Box Visualization** block and connect it to the Custom Python Block. This draws a box around each detected hole and the mounting bracket directly on the output image, which is the first thing you'll want to check before trusting the measurement that comes out of the Python block.\n\nWith the boxes drawn, you can immediately spot whether Gemini found both holes in roughly the right place, before you even look at the pass/fail result.\n\n### Step 7: Add a Label Visualization Block\n\nAdd a **Label Visualization** block and connect it to the Bounding Box Visualization block. This overlays the class name for each detection, `left_hole`\n\nor `right_hole`\n\n, right next to its bounding box, so you can confirm at a glance that neither hole got mislabeled.\n\n### Step 8: Display the Inspection Result\n\nAdd a **Text Display** block and connect it to the Label Visualization block, so the text gets overlaid on top of the already-annotated image. In the **Text** field, enter the following:\n\n```\nInspection: {{ $parameters.result }}\nDistance: {{ $parameters.distance }} px\n```\n\nThen fill in **Text Parameters** to map those template variables back to the Python block's outputs:\n\n```\n{\n  \"result\": \"$steps.custom_python_block.result\",\n  \"distance\": \"$steps.custom_python_block.measured_distance\"\n}\n```\n\nNow the output image shows the annotated bracket, the pass/fail verdict, and the exact measured distance all in one place, so you don't have to cross-reference the raw JSON to see why a part failed.\n\n### Step 9: Test the Workflow\n\nWith every block connected, click the **Test** icon in the upper-right corner of the Workflow editor and upload a bracket image. Once the workflow finishes running, you'll see whether the part **PASSES** or **FAILS** inspection based on the measured hole spacing. The output will also display the measured center-to-center distance between the two mounting holes in pixels, allowing you to verify the measurement used to determine the inspection result.\n\n## Detect Dimensional Defects with Computer Vision Conclusion\n\nIn this blog, we explored what dimensional defects are, looked at several common examples, and built a Roboflow Workflow that automatically inspects the spacing between two mounting holes on a manufactured part. Using Google Gemini to detect the relevant features and a small Python block to perform the measurement, we created a simple dimensional inspection pipeline capable of determining whether a part falls within an acceptable tolerance.\n\nWhile this example focused on hole spacing, the same workflow can be adapted to many other dimensional inspection tasks, including measuring gaps, verifying component alignment, checking connector positions, or validating overall part dimensions. By combining computer vision with automated measurement, manufacturers can perform consistent, repeatable inspections at scale while reducing the need for manual quality control.\n\n**Further reading:**\n\n**Cite this Post**\n\nUse the following entry to cite this post in your research:\n\n[Yajat Mittal](/author/yajat/). (Jul 8, 2026).\nDimensional Defect Inspection with Vision AI. Roboflow Blog: https://blog.roboflow.com/dimensional-defect-inspection-with-vision-ai/", "url": "https://wpnews.pro/news/dimensional-defect-inspection-with-vision-ai", "canonical_source": "https://blog.roboflow.com/dimensional-defect-inspection-with-vision-ai/", "published_at": "2026-07-08 16:01:43+00:00", "updated_at": "2026-07-08 16:23:26.045926+00:00", "lang": "en", "topics": ["computer-vision", "ai-tools", "ai-products"], "entities": ["Roboflow", "Gemini"], "alternates": {"html": "https://wpnews.pro/news/dimensional-defect-inspection-with-vision-ai", "markdown": "https://wpnews.pro/news/dimensional-defect-inspection-with-vision-ai.md", "text": "https://wpnews.pro/news/dimensional-defect-inspection-with-vision-ai.txt", "jsonld": "https://wpnews.pro/news/dimensional-defect-inspection-with-vision-ai.jsonld"}}