# POINT-CLOUD-ALGORITHM
**Repository Path**: WZhewei/point-cloud-algorithm
## Basic Information
- **Project Name**: POINT-CLOUD-ALGORITHM
- **Description**: 三维点云的焊锡缺陷检测
- **Primary Language**: Python
- **License**: AGPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 1
- **Created**: 2022-07-03
- **Last Updated**: 2025-04-02
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 简介
-----
该仓库利用三维点云数据进行焊锡缺陷检测,包括以下模块:
- 可视化模块
- 相机数据采集模块
- 焊锡外观检测模块
- 焊锡体积计算模块(正面 & 侧面)
- 飞锡检测模块
### 结构说明
```bash
├─main.py # 主函数
|
├─test_main.py # 测试文件,生产环境中不使用
|
├─global_cfg.json # 配置文件(焊锡大致范围、飞锡阈值等)
|
├─doc # 文档
│
└─utils # 工具函数
|
├─AI_2d # 焊锡外观检测
| |
| ├─inference # 外观推理
| |
| └─preprocessing/v2 # 点云数据预处理
|
├─MQ # MQ工具
|
|─camera # 相机模块
|
|─detection_3d # 体积计算与飞锡检测模块
|
|─visualization # 数据可视化模块
|
└─tool_function # 实验工具函数,生产环境中不使用
```
### 焊锡样件展示
- 正面焊锡

- 侧面焊锡

### MQ信道说明
- epai.aiCheck
- 算法将心跳信号以及返回结果放入该信道
- epai.point.cloud.AIQueue
- 后端发送任务文件到该信道
### 任务id说明
```json
{
"30": "3d_volume", # 体积计算选择
"31": "step_modify", # 修改步长
"40": "tin_beads_detect", # 锡珠判断
"50": "PIN_appearance_detect", # PIN针形状判断
"60": "NPY CONVERT TO PCD", # npy文件转换为pcd文件
"101": "Camera No. Change", # 相机程序号修改
"102": "Camera Data Get", # 相机数据获取
"110": "AI Preprocessing Detection",# 外观检测数据预处理
"115": "AI Inference Detection", # 外观形态推理
"116": "AI Preprocessing & AI Inference Detection" # 外观检测数据预处理+外观形态推理
}
```
### 体积计算步长参数修改
- 功能说明
修改相机竖直方向与侧面方向的步长
- 文件目录 ``utils/detection_3d/calculate_cfg.json``
- 文件内容
```json
{
"x_step_side": "12.5",
"y_step_side": "22",
"x_step_up": "32",
"y_step_up": "12.5",
"std-4-3": "utils/detection_3d/std-4-3.npy",
"std-4-4": "utils/detection_3d/std-4-4.npy",
"std-4-5": "utils/detection_3d/std-4-5.npy"
}
```
- std文件为飞锡检测的标准件
### 体积计算接口
- 功能说明
通过mq传递npy文件的地址让算法对其进行三维点云数据的体积计算
- params
| 参数 | 必选 | 类型 | 说明 | 举例 |
| ---------------- | ---- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
体积计算选择30 | 30 |
| point_cloud_file | True | string | npy文件路径(调试继续传之前的pcd文件路径即可,侧面体积要传npy文件) | D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\3d_pcd\\OK_front_40.npy |
| direction | True | int | 文件方向,0是正面文件,1是侧面文件 | 1
0 |
示例:
```json
{
"task_id": 666,
"task_type": "30",
"point_cloud_file": r"D:\hycx_work\point_cloud-deal\detection_3d\data\2022-03-01-normal-step_modify22\35051772613505277134A28022200109563_up_2022-02-28-11-22-09.npy",
"direction": 0
}
```
- return
```json
{
"task_id": 666,
"task_type": "3d_volume",
"point_cloud_file": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\3d_pcd\\OK_front_40.npy",
"direction": 1,
"Pin_1_V": 7.123,
"Pin_2_V": 7.123,
"Pin_3_V": 7.123
}
```
### 锡珠检测接口
- 功能说明
判断三个特殊区域是否有锡珠
- params
| 参数 | 必选 | 类型 | 说明 | 举例 |
| --------- | ---- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
锡珠判断40 | 40 |
| png | True | string | 图像文件 | D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.jpg |
| npy | True | string | npy文件 | D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.npy |
示例:
```json
{
"task_id": 777,
"task_type": 40,
"png": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.jpg",
"npy": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.npy”,
}
```
- return
```Special_Position1```为1表示有锡珠,0表示没有,共返回三个区域
```json
{
"task_id": 666,
"task_type": "tin_beads_detect",
"npy": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.npy",
"4-3": 1,
"4-4": 0,
"4-5": 1
}
```
### ~~正面形状检测接口~~
- ~~功能说明~~
~~判断三个PIN针的形状是否合格~~
- ~~params~~
| 参数 | 必选 | 类型 | 说明 | 举例 |
| --------- | ---- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
~~PIN针形状判断50~~ | 50 |
| file | True | string | 图像文件 | D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.jpg |
示例:
```json
{
"task_id": 888,
"task_type": 50,
"file": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.jpg"
}
```
- return
```Pin1_Up_Appearance```为1表示不合格,0表示合格
```json
{
"task_id": 666,
"task_type": "PIN_appearance_detect",
"file": "D:\\hycx_work\\point_cloud-deal\\detection_3d\\data\\test.jpg",
"Pin1_Up_Appearance": 1,
"Pin2_Up_Appearance": 0,
"Pin3_Up_Appearance": 1
}
```
### 点云数据转换接口
- 功能说明
将npy格式的点云数据转换为pcd格式的点云数据
- params
| 参数 | 必选 | 类型 | 说明 | 举例 |
| ------------ | ---- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
npy文件转换为pcd文件60 | “60” |
| npy | True | str | 需要预处理的npy路径
**注意:**目录应为绝对路径,npy和亮度图源数据所在目录应一致,否则无法查找 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21.npy" |
| targetFolder | True | str | 预处理文件的存储目录 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output" |
### 数据预处理接口
- 功能说明
对生成的npy文件及亮度图进行预处理,如有效区域提取、数据对齐、数据融合等,并将处理结果保存在**targetFolder**中
- params
| 参数 | 必选 | 类型 | 说明 | 举例 |
| ------------ | ---- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
外观检测数据预处理110 | “110” |
| npy | True | str | 需要预处理的npy路径
**注意:**目录应为绝对路径,npy和亮度图源数据所在目录应一致,否则无法查找 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21.npy" |
| targetFolder | True | str | 预处理文件的存储目录 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output" |
- return
```json
{
"task_id": 666,
"task_type": "110",
"image_output": "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21_meta_channelsBlend.png"
}
```
### 推理接口
- 功能说明
对于已经完成预处理的图片进行推理操作
- params
| 参数 | 必选 | 类型 | 说明 | 举例 |
| ---------------- | ----- | ---- | ------------------------------------------------------------ | --------------------- |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
外观形态推理115 | “115” |
| img_path | True | str | 预处理后的图片所在路径 | "/home/hycx/test.png" |
| detection_target | False | str | 推理后的结果图片存储目录,不传路径则不会生成结果 | “/home/hycx/result” |
- return
```json
{
"task_id": 666,
"task_type": "PIN_AI_DETECTION",
"img_path": "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21_meta_channelsBlend.png",
"Pin1_Up_Appearance": "nok",
"Pin2_Up_Appearance": "ok",
"Pin3_Up_Appearance": "unknown",
"detection_result_image": "/home/hycx/result/3505277134ML085B085301110012200465_up_2022-06-28-09-04-52_result.png"
}
```
### 预处理+推理接口
- 功能说明
| 参数 | 必选 | 类型 | 说明 | 举例 |
| ---------------- | ----- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| task_id | True | int | 任务id | 666 |
| task_type | True | str | 任务类型,根据类型调用不同的函数
外观检测数据预处理+外观形态推理116 | “116” |
| npy | True | str | 需要预处理的npy路径
**注意:**目录应为绝对路径,npy和亮度图源数据所在目录应一致,否则无法查找 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21.npy" |
| targetFolder | True | str | 预处理文件的存储目录 | "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output" |
| detection_target | False | str | 推理后的结果图片存储目录,不传路径则不会生成结果 | “/home/hycx/result” |
**该任务在预处理后会自动执行推理任务**
- return
```json
{
"task_id": 666,
"task_type": "PIN_AI_DETECTION",
"img_path": "/home/hycx/PONINT_ALGORITHM_DATA_TEST/output/2022-06-28/3505277134ML085B085301110012200465_side_2022-06-28-09-05-21_meta_channelsBlend.png",
"Pin1_Up_Appearance": "nok",
"Pin2_Up_Appearance": "ok",
"Pin3_Up_Appearance": "unknown",
"detection_result_image": "/home/hycx/result/3505277134ML085B085301110012200465_up_2022-06-28-09-04-52_result.png"
}
```
## 相机相关接口
#### 1. 相机切换程序
- 参数:
| 参数 | 必选 | 类型 | 说明 |
| ------------- | ---- | ---- | ------------------------------------------------------------ |
| programNo_set | True | int | 0 1 2 3 |
| task_id | True | int | 任务id |
| task_type | True | str | 任务类型,根据类型调用不同的函数
相机程序号修改101 |
- 返回:
data字段里返回当前的活跃程序``activate_programNo_set``,``ori_programNo_set``是原来的活跃程序。通过判断给的切断程序号以及活跃程序号判断是否改变成功,``change_status``为1是成功,为0修改是失败,-1就是相机出现问题通讯失败
```json
{
"ori_programNo_set": 0,
"activate_programNo_set": 1,
"change_status": 1
}
```
```json
{
"ori_programNo_set": 1,
"activate_programNo_set": 4,
"change_status": 0
}
```
```json
{
"ori_programNo_set": false,
"activate_programNo_set": false,
"change_status": -1
}
```
#### 2. 相机拿数据
- 参数:
| 参数 | 必选 | 类型 | 说明 |
| --------- | ---- | ---- | ------------------------------------------------------------ |
| dmc | True | str | 0 |
| direction | True | int | 正面数据或者侧面数据
正面为1
侧面为0 |
| task_id | True | int | 任务id |
| task_type | True | str | 任务类型,根据类型调用不同的函数
相机数据获取102 |
- 返回:
获取失败的msg汇总
| msg |
| ------------------------------------------------------------ |
| LJX8IF_InitializeHighSpeedDataCommunicationSimpleArray Error |
| LJX8IF_PreStartHighSpeedDataCommunication Error |
| LJX8IF_StartHighSpeedDataCommunication Error |
| Failed to acquire image (timeout) |
```json
{
"msg": "LJX8IF_InitializeHighSpeedDataCommunicationSimpleArray Error",
"get_status": -1
}
```
```json
{
"msg": "get success",
"get_status": 1
}
## 开源许可证
该项目采用 [AGPL](LICENSE)。
## 引用
如果你在研究中使用了本项目的代码,请参考如下 bibtex 引用 Training-Platform。
```
@article{epai-algorithm,
title = {{point-cloud-algorithm}: 3D point cloud, solder defect detection },
author = {HYCX, Bosch HUAYU Steering Systems},
year={2023}
}
```