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.
- 图像特征匹配 / Image Feature Matching: 使用ORB算法进行特征点检测和匹配
- 智能聚类筛选 / Intelligent Clustering: 采用DBSCAN算法筛选密集匹配点,排除假阳性
- 图像尺寸自适应 / Adaptive Image Sizing: 自动调整大图像尺寸以优化处理性能
- 匹配质量评估 / Match Quality Assessment: 多维度评估匹配质量,包括密度、覆盖率等指标
- Web文件上传 / Web File Upload: 提供Flask Web接口用于文件上传和管理
- 可视化结果 / Visualization Results: 生成匹配结果的可视化图像
- 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: 数值计算
- Python 3.13或更高版本
- pip包管理器
- 克隆项目 / Clone the repository:
git clone <repository-url>
cd pcbcd- 安装依赖 / Install dependencies:
pip install -r requirements.txt或者使用uv / Or using uv:
uv sync运行Flask应用 / Run Flask application:
python app.py服务将在 http://localhost:8000 启动
The service will start at http://localhost:8000
POST /uploadShoot
上传图片文件,返回GUID标识符 Upload image file and return GUID identifier
请求参数 / Request Parameters:
file或image: 图片文件fileorimage: Image file
响应 / Response:
{
"guid": "unique-identifier-string"
}在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
)| 参数 / 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 |
| 参数 / Parameter | 默认值 / Default | 描述 / Description |
|---|---|---|
eps |
20 | 邻域半径 / Neighborhood radius |
min_samples |
8 | 最小样本数 / Minimum number of samples |
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
-
图像读取与预处理 / Image Reading and Preprocessing
- 读取模板图像和待匹配图像
- 自动调整大尺寸图像
-
特征提取 / Feature Extraction
- 使用ORB算法提取特征点和描述符
- 分别处理模板图像和目标图像
-
特征匹配 / Feature Matching
- 使用暴力匹配算法进行特征匹配
- 应用交叉验证提高匹配准确性
-
聚类筛选 / Clustering Filter
- 使用DBSCAN算法对匹配点进行聚类
- 筛选出密集的匹配点,排除孤立点
-
质量评估 / Quality Assessment
- 计算匹配点密度比例
- 评估特征覆盖率
- 综合判断匹配质量
-
结果可视化 / Result Visualization
- 绘制匹配关键点
- 显示匹配连线
- 保存可视化结果
- 图像缩放 / Image Scaling: 自动缩放超大图像,提高处理速度
- 特征点数量控制 / Feature Point Control: 合理设置ORB特征点数量(默认500个)
- 并行处理 / Parallel Processing: 支持多线程处理文件上传
- 确保模板图像和待匹配图像具有足够的特征点
- 对于大尺寸图像,系统会自动进行缩放处理
- 匹配结果会保存为
match_result.png文件 - 文件上传后会生成唯一的GUID用于标识
本项目采用MIT许可证 / This project is licensed under the MIT License.
欢迎提交Issue和Pull Request来改进项目 / Issues and Pull Requests are welcome to improve the project.
如有问题或建议,请通过以下方式联系 / For questions or suggestions, please contact:
- 提交Issue / Submit an Issue
- 发送邮件 / Send an email
版本 / Version: 0.1.0
更新日期 / Update Date: 2025年12月