Skip to content

ForePhysics/PCBCDRecognition

Repository files navigation

PCBCD - PCB Circuit Board Detection

PCBCD - PCB电路板检测系统

项目简介 / Project Overview

PCBCD是一个基于计算机视觉的PCB电路板检测系统,使用ORB特征匹配和DBSCAN聚类算法来识别和定位电路板上的特定区域。

PCBCD is a computer vision-based PCB circuit board detection system that uses ORB feature matching and DBSCAN clustering algorithms to identify and locate specific areas on circuit boards.

功能特性 / Features

  • 图像特征匹配 / Image Feature Matching: 使用ORB算法进行特征点检测和匹配
  • 智能聚类筛选 / Intelligent Clustering: 采用DBSCAN算法筛选密集匹配点,排除假阳性
  • 图像尺寸自适应 / Adaptive Image Sizing: 自动调整大图像尺寸以优化处理性能
  • 匹配质量评估 / Match Quality Assessment: 多维度评估匹配质量,包括密度、覆盖率等指标
  • Web文件上传 / Web File Upload: 提供Flask Web接口用于文件上传和管理
  • 可视化结果 / Visualization Results: 生成匹配结果的可视化图像

技术栈 / Technology Stack

  • Python 3.13+
  • Flask 3.1.2+: Web框架
  • OpenCV 4.12.0+: 计算机视觉库
  • scikit-image 0.25.2+: 图像处理库
  • scikit-learn 1.7.1+: 机器学习库
  • matplotlib 3.10.5+: 数据可视化
  • NumPy: 数值计算

安装 / Installation

环境要求 / Requirements

  • Python 3.13或更高版本
  • pip包管理器

安装步骤 / Installation Steps

  1. 克隆项目 / Clone the repository:
git clone <repository-url>
cd pcbcd
  1. 安装依赖 / Install dependencies:
pip install -r requirements.txt

或者使用uv / Or using uv:

uv sync

使用方法 / Usage

1. 启动Web服务 / Start Web Service

运行Flask应用 / Run Flask application:

python app.py

服务将在 http://localhost:8000 启动 The service will start at http://localhost:8000

2. 文件上传接口 / File Upload API

POST /uploadShoot

上传图片文件,返回GUID标识符 Upload image file and return GUID identifier

请求参数 / Request Parameters:

  • fileimage: 图片文件
  • file or image: Image file

响应 / Response:

{
  "guid": "unique-identifier-string"
}

3. 图像匹配功能 / Image Matching Function

在Jupyter笔记本中使用匹配功能 / Use matching function in Jupyter notebook:

from t import match_and_visualize

# 模板图片路径 / Template image path
template_path = 'template.png'

# 待匹配图片路径 / Image to match path
image_path = 'photo.jpg'

# 执行匹配 / Perform matching
matches, corners = match_and_visualize(
    template_path, 
    image_path, 
    min_matches=20, 
    density_threshold=0.7,
    max_pixels=1200**2
)

算法参数 / Algorithm Parameters

匹配质量参数 / Matching Quality Parameters

参数 / Parameter 默认值 / Default 描述 / Description
min_matches 20 最小匹配点数,低于此值认为匹配失败 / Minimum number of matches, below this value the match is considered failed
density_threshold 0.7 密集匹配点比例阈值 / Dense match point ratio threshold
max_pixels 1200² 最大像素数限制,超过此值将自动缩放 / Maximum pixel limit, images larger than this will be automatically scaled

DBSCAN聚类参数 / DBSCAN Clustering Parameters

参数 / Parameter 默认值 / Default 描述 / Description
eps 20 邻域半径 / Neighborhood radius
min_samples 8 最小样本数 / Minimum number of samples

项目结构 / Project Structure

pcbcd/
├── app.py              # Flask Web应用 / Flask web application
├── main.py             # 主程序入口 / Main program entry
├── t.ipynb            # Jupyter笔记本,包含匹配算法 / Jupyter notebook with matching algorithms
├── pyproject.toml     # 项目配置文件 / Project configuration file
├── uploads/           # 上传文件存储目录 / Uploaded files storage directory
├── data/              # 数据文件存储目录 / Data files storage directory
└── README.md          # 项目说明文档 / Project documentation

算法流程 / Algorithm Flow

  1. 图像读取与预处理 / Image Reading and Preprocessing

    • 读取模板图像和待匹配图像
    • 自动调整大尺寸图像
  2. 特征提取 / Feature Extraction

    • 使用ORB算法提取特征点和描述符
    • 分别处理模板图像和目标图像
  3. 特征匹配 / Feature Matching

    • 使用暴力匹配算法进行特征匹配
    • 应用交叉验证提高匹配准确性
  4. 聚类筛选 / Clustering Filter

    • 使用DBSCAN算法对匹配点进行聚类
    • 筛选出密集的匹配点,排除孤立点
  5. 质量评估 / Quality Assessment

    • 计算匹配点密度比例
    • 评估特征覆盖率
    • 综合判断匹配质量
  6. 结果可视化 / Result Visualization

    • 绘制匹配关键点
    • 显示匹配连线
    • 保存可视化结果

性能优化 / Performance Optimization

  • 图像缩放 / Image Scaling: 自动缩放超大图像,提高处理速度
  • 特征点数量控制 / Feature Point Control: 合理设置ORB特征点数量(默认500个)
  • 并行处理 / Parallel Processing: 支持多线程处理文件上传

注意事项 / Notes

  • 确保模板图像和待匹配图像具有足够的特征点
  • 对于大尺寸图像,系统会自动进行缩放处理
  • 匹配结果会保存为match_result.png文件
  • 文件上传后会生成唯一的GUID用于标识

许可证 / License

本项目采用MIT许可证 / This project is licensed under the MIT License.

贡献 / Contributing

欢迎提交Issue和Pull Request来改进项目 / Issues and Pull Requests are welcome to improve the project.

联系方式 / Contact

如有问题或建议,请通过以下方式联系 / For questions or suggestions, please contact:

  • 提交Issue / Submit an Issue
  • 发送邮件 / Send an email

版本 / Version: 0.1.0
更新日期 / Update Date: 2025年12月

About

识别PCB CD上的贴纸图案

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors