A web application that demonstrates how machine learning and computer vision can be used to detect defects in printed circuit boards (PCBs). This project is intended for educational purposes to show how computers can help in manufacturing quality control.
This application allows users to upload images of PCBs and uses computer vision techniques to classify them into different defect categories:
- Missing Hole - A hole that should be present is missing
- Mouse Bite - Part of the copper is damaged, creating a bite-like appearance
- Open Circuit - A break in the circuit path that should be connected
- Short - Unintended connection between two points
- Spur - Unwanted projection from a conductor
- Spurious Copper - Unwanted copper remnants in areas that should be clear
- Normal - No defect detected
- Python 3.7 or higher
- pip (Python package installer)
-
Clone this repository:
git clone https://github.com/yourusername/pcb-defect-detection.git cd pcb-defect-detection -
Create and activate a virtual environment (recommended):
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate -
Install the required dependencies:
pip install -r requirements.txt -
Run the setup script:
python setup_project.pyThis will:
- Create the necessary directory structure
- Generate synthetic PCB images for testing
- Create a dummy model for demonstration
-
Run the application:
python app.py -
Open your browser and navigate to
http://localhost:5000
- Upload an Image: Click the "Choose File" button and select a PCB image
- Analyze: Click the "Analyze PCB" button to process the image
- View Results: See the detection results, including:
- Detected defect type (if any)
- Confidence level
- Information about the defect
- Recommended action
- View Feature Detection: For advanced users, click "View Feature Detection" to see how the image is processed
The application uses several computer vision techniques to detect PCB defects:
- Preprocessing: The uploaded image is resized and normalized
- Feature Extraction:
- Contour detection to identify PCB components
- Edge detection to find traces and connections
- Circle detection to locate holes
- Classification: Features are analyzed to determine the most likely defect type
- Visualization: Detection results are displayed with feature highlighting
In a production environment, this would be enhanced with deep learning models trained on thousands of labeled PCB images.
This demo is inspired by the PCB defects dataset which contains: https://www.kaggle.com/datasets/akhatova/pcb-defects
- 1386 images with 6 types of defects
- Each defect is annotated with bounding boxes
- The dataset simulates real manufacturing defects in PCBs
For educational purposes, this demo uses synthetic images, but the concepts apply to real-world PCB inspection.
Here are some ways this project could be extended:
- Real ML Model: Train an actual deep learning model on a PCB defect dataset
- Object Detection: Implement localization to identify where defects occur on the PCB
- Multiple Defect Detection: Detect multiple defects in a single image
- Real-time Video Analysis: Analyze PCBs from a webcam or video feed
- Detailed Analytics: Track defect statistics and generate reports
Contributions are welcome! If you'd like to improve this project:
- Fork the repository
- Create a new branch (
git checkout -b feature/awesome-feature) - Make your changes
- Commit your changes (
git commit -m 'Add awesome feature') - Push to the branch (
git push origin feature/awesome-feature) - Open a Pull Request
- Based on PCB defect detection research in manufacturing
- Inspired by automated optical inspection (AOI) systems used in electronics manufacturing
- Created for educational purposes to demonstrate computer vision applications