Files
ailai_image_point_diff/point_diff_main/README.md

95 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# RKNN 关键点推理与偏移量计算工具
该工具通过使用RKNN模型对输入图像进行关键点检测并根据检测结果计算相对于固定参考点的偏移量单位毫米。此外还提供了可视化选项来展示计算结果。
## 目录结构
├── calculate_offset.py # 主程序脚本
├── point.rknn # RKNN 模型文件 (请确保正确路径)
└── README.md # 说明文档
## 配置
`calculate_offset.py` 文件顶部的配置区中,您可以修改如下参数以适应您的需求:
- **MODEL_PATH**: RKNN 模型文件路径。
- **OUTPUT_DIR**: 输出目录路径。
- **FIXED_REF_POINT**: 固定参考点坐标(像素)。
- **SCALE_X**, **SCALE_Y**: 缩放因子,用于将像素坐标转换为毫米。
- **IMG_SIZE**: 输入图像尺寸。
## 安装依赖
请确保安装了必要的 Python 库。可以通过 pip 安装:
```bash
pip install opencv-python numpy rknnlite
```
## 函数调用1.0
您也可以直接调用 calculate_offset_from_image 函数,以便集成到其他项目中:
示例 1: 仅获取偏移量(不画图)
```bash
from calculate_offset import calculate_offset_from_image
result = calculate_offset_from_image("your_image_path.jpg", visualize=False)
if result['success']:
print(f"Offset: DeltaX={result['dx_mm']:+.2f} mm, DeltaY={result['dy_mm']:+.2f} mm")
else:
print("Error:", result['message'])
```
示例 2: 获取偏移量并保存可视化图
```bash
from calculate_offset import calculate_offset_from_image
result = calculate_offset_from_image("your_image_path.jpg", visualize=True)
```
## 函数调用2.0
示例 1: 仅获取偏移量(不画图)
```bash
from calculate_diff2.0 import calculate_offset_from_image
result = calculate_offset_from_image("11.jpg", visualize=False)
if result['success']:
print(f"Offset: DeltaX={result['dx_mm']:+.2f} mm, DeltaY={result['dy_mm']:+.2f} mm")
else:
print("Error:", result['message'])
```
示例 2: 获取偏移量并保存可视化图
```bash
from calculate_diff2.0 import calculate_offset_from_image
result = calculate_offset_from_image("11.jpg", visualize=True)
```
##该函数返回一个包含下列字段的字典1.0
success: 成功标志True/False
dx_mm: 水平偏移(毫米)
dy_mm: 垂直偏移(毫米)
cx: 中心点 x 坐标(像素)
cy: 中心点 y 坐标(像素)
message: 错误信息或成功提示
##该函数返回一个包含下列字段的字典2.0
success: 成功标志True/False
dx_mm: 水平偏移(毫米)
dy_mm: 垂直偏移(毫米)
cx: 中心点 x 坐标(像素)
cy: 中心点 y 坐标(像素)
message: 错误信息或成功提示
class_id: 检测类别 ID #这里是bag的id是0
obj_conf: 检测置信度 #这就是识别为料袋的置信度
bbox: 检测矩形框 [x_left, y_top, width, height]
message: 错误信息或成功提示