Skip to content

ModinWang1/wire-defect-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wire Defect Detection Program

An automated computer vision system for detecting and classifying defects in wires/cables using OpenCV and C++.

📋 Project Description

What is this?

This is a software program that acts like an automated quality inspector for wires and cables. Just like how a human inspector would carefully examine a wire for problems, this program uses computer vision to automatically find defects in photographs of wires. This is not a trained model and uses nothing but the functions provided by OpenCV which allows it to be fast and run on minimal hardware.

What does it do?

When you give this program a photo of a wire or cable, it:

  1. Measures the wire - Automatically calculates how thick the wire is at different points (in pixels)
  2. Finds defects - Scans the entire wire for three types of manufacturing problems:
    • Pin holes: Small dark dots where material is missing
    • Cuts: Larger dark areas indicating damage or gaps
    • Scratches: Bright lines showing surface damage
  3. Creates visual reports - Generates new images with:
    • Red circles drawn around each defect found
    • Labels showing what type of defect each one is
    • Measurements showing wire thickness

Why is this useful?

In manufacturing, checking every wire by eye is:

  • Time consuming and expensive
  • Prone to human error (inspectors might miss small defects)
  • Difficult to maintain consistency

This automated system can inspect wires consistently, quickly, and document everything it finds, helping manufacturers maintain quality control. Currently works best with blue wires (see sample images provided)

🔧 Prerequisites

  • CMake 3.10+
  • OpenCV 4.x
  • C++17 compatible compiler
  • Visual Studio 2019/2022 (Windows) or GCC/Clang (Linux/Mac)

📁 Project Structure

wire-defect-detection/  
├── images/ # Input images (wire1.jpg - wire4.jpg)  
├── output/ # Generated output (created automatically)  
├── src/  
│ ├── main.cpp # Application entry point  
│ ├── preprocessing.cpp # Image preprocessing  
│ ├── defects.cpp # Defect detection algorithms  
│ └── measurements.cpp # Diameter measurement  
├── include/  
│ ├── preprocessing.h  
│ ├── defects.h  
│ └── measurements.h  
└── CMakeLists.txt

🚀 Quick Start

Building the Project

Windows (CMD):

mkdir build
cd build
cmake ..
cmake --build . --config Debug

Linux/Mac:

mkdir build
cd build
cmake ..
make

Running the Application

# Syntax: wire-defect-detection <image_path> <image_number>

# Windows
Debug\wire-defect-detection.exe ..\..\images\wire1.jpg 1

# Linux/Mac
./wire-defect-detection ..\../images/wire1.jpg 1

Processing All Images

Create a batch script to process all images:

Windows (process_all.bat):

@echo off
for %%i in (1,2,3,4) do (
    Debug\wire-defect-detection.exe ..\images\wire%%i.jpg %%i
    echo Processed image %%i
)

Linux/Mac (process_all.sh):

#!/bin/bash
for i in {1..4}; do
    ./wire-defect-detection ../../images/wire$i.jpg $i
done

📊 Output Files

File Description
Task 1: diameteroutput.jpg Wire with diameter measurements at 3 points
Task 2: defectoutput[1-4].jpg Detected defects circled in red
Task 3: classifyoutput[1-4].jpg Detected defects circled with labels

🔍 Defect Types

Pin Holes

  • Appearance: Small, dark, circular spots
  • Criteria: Area < 15% of wire width, aspect ratio 0.85-1.15

Cuts

  • Appearance: Larger dark regions with irregular shapes
  • Criteria: Dark areas that don't meet pin hole criteria

Scratches

  • Appearance: Bright, elongated marks
  • Criteria: Low saturation, elongated shape

⚙️ Algorithm Pipeline

1. Image Preprocessing
   ├── Grayscale conversion
   ├── Bilateral filtering
   └── Wire segmentation

2. Diameter Measurement
   ├── Edge detection
   ├── Width calculation at 25%, 50%, 75% height
   └── Visualization

3. Defect Detection
   ├── Dark defects (HSV value channel)
   │   ├── Adaptive thresholding
   │   ├── Edge exclusion
   │   └── Classification
   └── Bright defects (HSV saturation channel)
       ├── Threshold + region merging
       └── Proximity filtering

🛠️ Configuration Parameters

// Key parameters (in defects.cpp)
const int EDGE_EROSION_SIZE = 11;        // Edge exclusion kernel
const int ADAPTIVE_BLOCK_SIZE = 27;      // Adaptive threshold window
const int SATURATION_THRESHOLD = 40;     // Scratch detection threshold
const int DEFECT_MERGE_SIZE = 17;        // Scratch merging kernel
const int MIN_DEFECT_AREA = 4;           // Minimum defect size (pixels)

📈 Performance

  • Processing Time: ~500ms per image
  • Supported Formats: JPEG, PNG, BMP
  • Recommended Resolution: 1000x3000 pixels

🐛 Troubleshooting

Issue Solution
"Can't read image" Check file path and format
No defects detected Adjust threshold parameters
Build errors Verify OpenCV installation
Missing output folder Program creates it automatically

📝 Example Usage

# Single image processing
Debug\wire-defect-detection.exe C:\path\to\wire_image.jpg 1

# Expected console output:
Saved diameteroutput.jpg: "C:\\Users\\modin\\Projects\\wire-defect-detection\\output"
Saved visualization: defectoutput4.jpg
Saved classification visualization: classifyoutput4.jpg

👥 Contributors

  • Modin Wang

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published