Files
wood_vis/README.md
2026-02-25 14:24:05 +08:00

113 lines
2.1 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.

# 木条检测与分类 Python 接口示例
本项目提供完整的 Python 示例,用于图像中木条数量检测、存在性判定以及 NG 木条异常分类。
它支持:
- 基于 RKNNLite 的木条检测
- NG/OK 木条判定
- NG 木条异常类型分类
- 简单接口调用,支持本地图片推理
---
## 目录结构
wood_detection/
├── wood_detect/
│ ├── wood_detect.py # 木条数量检测接口
│ └── wood_detect.rknn # RKNN模型文件
├── wood_exist/
│ ├── wood_exist.py # 木条存在性判定接口
│ └── wood_exist_cls.rknn # RKNN模型文件
├── wood_ng/
│ ├── wood_ng.py # NG木条异常分类接口
│ └── wood_ng_cls.rknn # RKNN模型文件
└── README.md # 说明文档
---
## 配置
### 安装依赖
```bash
pip install opencv-python numpy rknnlite
```
## 接口说明
### 1. 木条数量检测
函数detect_wood(img: np.ndarray) -> int
参数:
imgBGR格式图像 (np.ndarray)
返回值:
检测到的木条数量 (int)
示例:
#### 函数调用
```python
import cv2
from wood_detect.wood_detect import detect_wood
img = cv2.imread("1.jpg")
result = detect_wood(img)
print(f"检测到木条数量: {result}")
```
### 2. 木条存在性判定
函数classify_wood_exist(img: np.ndarray) -> int
参数:
imgBGR格式图像 (np.ndarray)
返回值:
整数结果对应木条状态int: 存在结果0 / 1
示例:
```python
import cv2
from wood_exist.wood_exist import classify_wood_exist, CLASS_NAMES
img = cv2.imread("1.png")
result = classify_wood_exist(img)
print(f"木条存在性判定: {result}")
```
### 3. NG 木条异常分类
函数classify_wood_ng(img: np.ndarray) -> int
参数:
imgBGR格式图像 (np.ndarray)
返回值:
整数结果,对应 NG木条int: NG结果0 / 1
示例:
```python
import cv2
from wood_ng.wood_ng import classify_wood_ng, CLASS_NAMES
img = cv2.imread("1.png")
result = classify_wood_ng(img)
print(f"NG 木条: {result}")
```