defect-detection-ai
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.
Install / Use
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-aiInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Education & ResearchSupported Platforms
Our assessment of defect-detection-ai
defect-detection-ai scores 91/100 on our quality scale, 148th of 422 Education & Research skills we index (top 36%).
Its SKILL.md is 27 KB long, well organised into 16 sections with 5 code examples: a thorough specification that gives an agent plenty to work with.
It has 333 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated about 3 months ago, so defect-detection-ai is actively maintained.
- Our last check on 2026-11-20 found the source still online.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.
AI review by kimi-k2.7-code on 2026-10-07. Automated pattern scan on 2026-10-07. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
defect-detection-ai compared with similar skills
All 4 of these similar skills score higher than defect-detection-ai; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| defect-detection-ai (this skill)by datadrivenconstruction | 91 | 333 | 3mo ago | SKILL.md |
| taste-skillby Leonxlnx | 100 | 118.9k | 11d ago | CLAUDE.md |
| Agent-Reachby Panniantong | 100 | 113.3k | 12d ago | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 80.2k | today | CLAUDE.md |
| last30days-skillby mvanhorn | 100 | 70.9k | today | CLAUDE.md |
Frequently asked questions
- How do I install defect-detection-ai?
- Run
npx skills add datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction --skill defect-detection-ai. The install tabs above show the steps for each supported agent. - Which AI agents does defect-detection-ai work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is defect-detection-ai safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is defect-detection-ai still maintained?
- The repository was last updated about 3 months ago, so defect-detection-ai is actively maintained.
Skill content
View source on GitHubname: "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
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([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
self.classes = list(DefectType)
def predict(self, image_path: str) -> DefectDetection:
"""Classify defect in image"""
image = Image.open(image_path).convert('RGB')
input_tensor = self.transform(image).unsqueeze(0)
with torch.no_grad():
outputs = self.model(input_tensor)
probs = torch.softmax(outputs, dim=1)
confidence, predicted = torch.max(probs, 1)
defect_type = self.classes[predicted.item()]
return DefectDetection(
defect_type=defect_type,
confidence=confidence.item(),
severity=self._estimate_severity(confidence.item()),
bounding_box=(0, 0, image.width, image.height),
area_ratio=1.0
)
def _estimate_severity(self, confidence: float) -> SeverityLevel:
if confidence > 0.9:
return SeverityLevel.CRITICAL
elif confidence > 0.7:
return SeverityLevel.SEVERE
elif confidence > 0.5:
return SeverityLevel.MODERATE
else:
return SeverityLevel.MINOR
# Usage
classifier = SimpleDefectClassifier()
# result = classifier.predict("concrete_image.jpg")
# print(f"Defect: {result.defect_type.value}, Confidence: {result.confidence:.2%}")
Comprehensive Defect Detection System
Object Detection Model
import torch
import torch.nn as nn
from torchvision import transforms
from torchvision.models.detection import fasterrcnn_resnet50_fpn
from PIL import Image
import numpy as np
from dataclasses import dataclass, field
from typing import List, Dict, Tuple, Optional
from datetime import datetime
import json
@dataclass
class BoundingBox:
x1: int
y1: int
x2: int
y2: int
@property
def width(self) -> int:
return self.x2 - self.x1
@property
def height(self) -> int:
return self.y2 - self.y1
@property
def area(self) -> int:
return self.width * self.height
@property
def center(self) -> Tuple[int, int]:
return ((self.x1 + self.x2) // 2, (self.y1 + self.y2) // 2)
@dataclass
class DetectedDefect:
defect_id: str
defect_type: DefectType
confidence: float
severity: SeverityLevel
bounding_box: BoundingBox
area_sqm: Optional[float] = None
dimensions_mm: Optional[Tuple[float, float]] = None
metadata: Dict = field(default_factory=dict)
@dataclass
class InspectionResult:
inspection_id: str
image_path: str
timestamp: datetime
location: str
element_type: str
defects: List[DetectedDefect]
overall_condition: str
recommended_actions: List[str]
class DefectDetectionModel:
"""Deep learning defect detection with object detection"""
DEFECT_CLASSES = {
1: DefectType.CRACK,
2: DefectType.SPALLING,
3: DefectType.CORROSION,
4: DefectType.HONEYCOMBING,
5: DefectType.EFFLORESCENCE,
6: DefectType.DEFORMATION,
7: DefectType.SURFACE_DAMAGE
}
def __init__(self, model_path: str = None, device: str = 'cpu'):
self.device = torch.device(device)
# Initialize Faster R-CNN
self.model = fasterrcnn_resnet50_fpn(pretrained=True)
# Modify for our classes
num_classes = len(self.DEFECT_CLASSES) + 1 # +1 for background
in_features = self.model.roi_heads.box_predictor.cls_score.in_features
self.model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
if model_path:
self.model.load_state_dict(torch.load(model_path, map_location=self.device))
self.model.to(self.device)
self.model.eval()
self.transform = transforms.Compose([
transforms.ToTensor()
])
def detect(self, image_path: str, confidence_threshold: float = 0.5,
pixels_per_mm: float = None) -> List[DetectedDefect]:
"""Detect defects in image"""
image = Image.open(image_path).convert('RGB')
image_tensor = self.transform(image).to(self.device)
with torch.no_grad():
predictions = self.model([image_tensor])
pred = predictions[0]
defects = []
for i in range(len(pred['boxes'])):
score = pred['scores'][i].item()
if score < confidence_threshold:
continue
label = pred['labels'][i].item()
box = pred['boxes'][i].cpu().numpy()
defect_type = self.DEFECT_CLASSES.get(label, DefectType.SURFACE_DAMAGE)
bbox = BoundingBox(
x1=int(box[0]),
y1=int(box[1]),
x2=int(box[2]),
y2=int(box[3])
)
# Calculate dimensions if scale provided
dimensions_mm = None
if pixels_per_mm:
width_mm = bbox.width / pixels_per_mm
height_mm = bbox.height / pixels_per_mm
dimensions_mm = (width_mm, height_mm)
severity = self._classify_severity(defect_type, bbox, image.size)
defects.append(DetectedDefect(
defect_id=f"DEF-{i:04d}",
defect_type=defect_type,
confidence=score,
severity=severity,
bounding_box=bbox,
dimensions_mm=dimensions_mm
))
return defects
def _classify_severity(self, defect_type: DefectType,
bbox: BoundingBox,
image_size: Tuple[int, int]) -> SeverityLevel:
"""Classify defect severity based on type and size"""
image_area = image_size[0] * image_size[1]
defect_ratio = bbox.area / image_area
# Severity thresholds by defect type
thresholds = {
DefectType.CRACK: {'critical': 0.1, 'severe': 0.05, 'moderate': 0.02},
DefectType.SPALLING: {'critical': 0.15, 'severe': 0.08, 'moderate': 0.03},
DefectType.CORROSION: {'critical': 0.2, 'severe': 0.1, 'moderate': 0.05},
DefectType.HONEYCOMBING: {'critical': 0.1, 'severe': 0.05, 'moderate': 0.02},
DefectType.DEFORMATION: {'critical': 0.05, 'severe': 0.02, 'moderate': 0.01}
}
t = thresholds.get(defect_type, {'critical': 0.15, 'severe': 0.08, 'moderate': 0.03})
if defect_ratio >= t['critical']:
return SeverityLevel.CRITICAL
elif defect_ratio >= t['severe']:
return SeverityLevel.SEVERE
elif defect_ratio >= t['moderate']:
return SeverityLevel.MODERATE
else:
return SeverityLevel.MINOR
class FastRCNNPredictor(nn.Module):
"""Custom predictor for Faster R-CNN"""
def __init__(self, in_channels, num_classes):
super().__init__()
self.cls_score = nn.Linear(in_channels, num_classes)
self.bbox_pred = nn.Linear(in_channels, num_classes * 4)
def forward(self, x):
scores = self.cls_score(x)
bbox_deltas = self.bbox_pred(x)
return scores, bbox_deltas
Crack Analysis System
import cv2
import numpy as np
from typing import List, Tuple, Dict
class CrackAnalyzer:
"""Specialized crack detection and measurement"""
def __init__(self):
self.min_crack_length = 10 # pixels
self.min_crack_width = 2 # pixels
def detect_cracks(self, image_path: str,
pixels_per_mm: float = 1.0) -> List[Dict]:
"""Detect and measure cracks in image"""
# Load image
image = cv2.imread(image_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Enhance contrast
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
enhanced = clahe.apply(gray)
# Edge detection
edges = cv2.Canny(enhanced, 50, 150)
# Morphological operations to connect crack segments
kernel = np.ones((3, 3), np.uint8)
dilated = cv2.dilate(edges, kernel, iterations=1)
closed = cv2.morphologyEx(dilated, cv2.MORPH_CLOSE, kernel)
# Find contours
contours, _ = cv2.findContours(closed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cracks = []
for i, contour in enumerate(contours):
# Filter by length
arc_length = cv2.arcLength(contour, False)
if arc_length < self.min_crack_length:
continue
# Get bounding box
x, y, w, h = cv2.boundingRect(contour)
# Calculate crack properties
length_px = arc_length
width_px = self._estimate_crack_width(gray, contour)
# Convert to mm
length_mm = length_px / pixels_per_mm
width_mm = width_px / pixels_per_mm
# Classify crack
crack_type = self._classify_crack(length_mm, width_mm, contour)
cracks.append({
'crack_id': f"CRACK-{i:04d}",
'type': crack_type,
'length_mm': length_mm,
'width_mm': width_mm,
'bounding_box': (x, y, x + w, y + h),
'contour': contour.tolist(),
'severity': self._get_crack_severity(width_mm, length_mm),
'orientation': self._get_crack_orientation(contour)
})
return cracks
def _estimate_crack_width(self, gray_image: np.ndarray,
contour: np.ndarray) -> float:
"""Estimate average crack width"""
# Create mask for contour
mask = np.zeros(gray_image.shape, dtype=np.uint8)
cv2.drawContours(mask, [contour], -1, 255, 1)
# Distance transform
dist = cv
Truncated for display — read the full file on GitHub.
Related Skills
taste-skill
118.9kAgent skills that give coding agents taste: art direction, reference images and a browser check instead of generic AI pages
Agent-Reach
113.3kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
80.2kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
last30days-skill
70.9kAI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
