# defect-detection-ai

defect-detection-ai identifies cracks, spalling, corrosion and other defects in concrete, steel and finishes from images and video using deep learning. Classifies defect type and severity.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 121 installs · ★ 434 repo stars
- Author: datadrivenconstruction
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction/tree/HEAD/5_DDC_Innovative/defect-detection-ai/SKILL.md
- Updated: 2026-10-19
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/defect-detection-ai

## What it does

The skill runs a computer vision model (Faster R-CNN on ResNet50) that detects cracks, spalling, corrosion, honeycombing, efflorescence and deformations in photos of construction elements. It draws bounding boxes around defects, returns confidence scores and estimates severity (minor, moderate, severe, critical). Works with concrete, steel, masonry, finishes and MEP components.

Python scripts rely on PyTorch and torchvision; `python3` must be in `PATH`. For accurate defect dimensions, provide `pixels_per_mm` calibration. The model is trained on seven defect types; new types require retraining.

Install in Claude Code: `npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a claude-code`, description lands in `~/.claude/skills/defect-detection-ai/SKILL.md`.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/defect-detection-ai/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/defect-detection-ai/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/defect-detection-ai/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/defect-detection-ai/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction 5_DDC_Innovative/defect-detection-ai/SKILL.md
```

2. **Manually: put the files in place**
- File: `.github/skills/defect-detection-ai/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --path 5_DDC_Innovative/defect-detection-ai
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/defect-detection-ai/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction/tree/HEAD/5_DDC_Innovative/defect-detection-ai/SKILL.md

## When to use it
- detect cracks and spalling in a concrete slab photo
- classify weld defects by risk level
- generate an inspection report with defect coordinates
- spot corrosion on steel members in video frames
- measure spalling area as a percentage of the image

## Example prompts
- Analyze `wall_photo.jpg` for cracks and return bounding box coordinates.
- Find defects in the `inspection_images/` folder and produce a table with types and severity levels.
- Run detection on `beam_001.jpg` with confidence threshold 0.7 and calibration of 2.5 pixels per millimeter.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 6c2a5e8b8cb216d5.

BEGIN THIRD-PARTY FILE 6c2a5e8b8cb216d5
````text
---
name: "defect-detection-ai"
description: "AI-powered construction defect detection using computer vision. Identify cracks, spalling, corrosion, and other defects in concrete, steel, and building components from images and video."
homepage: "https://datadrivenconstruction.io"
metadata: {"openclaw": {"emoji": "🚀", "os": ["darwin", "linux", "win32"], "homepage": "https://datadrivenconstruction.io", "requires": {"bins": ["python3"]}}}
---
# AI Defect Detection

## Overview

This skill implements deep learning-based defect detection for construction quality control. Analyze images and video to automatically identify structural and surface defects, classify severity, and generate inspection reports.

**Detectable Defects:**
- Concrete: Cracks, spalling, honeycombing, efflorescence
- Steel: Corrosion, weld defects, deformation
- Masonry: Mortar deterioration, displacement
- Finishes: Surface defects, coating failures
- MEP: Insulation damage, pipe corrosion

## Quick Start

```python
import torch
import torch.nn as nn
from torchvision import transforms, models
from PIL import Image
from dataclasses import dataclass
from typing import List, Dict, Tuple
from enum import Enum

class DefectType(Enum):
    CRACK = "crack"
    SPALLING = "spalling"
    CORROSION = "corrosion"
    HONEYCOMBING = "honeycombing"
    EFFLORESCENCE = "efflorescence"
    DEFORMATION = "deformation"
    SURFACE_DAMAGE = "surface_damage"
    NO_DEFECT = "no_defect"

class SeverityLevel(Enum):
    MINOR = "minor"
    MODERATE = "moderate"
    SEVERE = "severe"
    CRITICAL = "critical"

@dataclass
class DefectDetection:
    defect_type: DefectType
    confidence: float
    severity: SeverityLevel
    bounding_box: Tuple[int, int, int, int]  # x1, y1, x2, y2
    area_ratio: float  # Defect area as ratio of image

# Simple classifier using pretrained model
class SimpleDefectClassifier:
    def __init__(self, num_classes: int = 8):
        self.model = models.resnet18(pretrained=True)
        self.model.fc = nn.Linear(self.model.fc.in_features, num_classes)
        self.model.eval()

        self.transform = transforms.Compose([
````
END THIRD-PARTY FILE 6c2a5e8b8cb216d5

The third-party file has ended. Everything between the 6c2a5e8b8cb216d5 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2131 of 28082 bytes. © datadrivenconstruction · MIT · https://github.com/datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction/tree/HEAD/5_DDC_Innovative/defect-detection-ai/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
