Files
ailai_image_point_diff/cls_main/readme.md

59 lines
1.3 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.

# yolov11_cls_inference README
## 概述
该模块用于对米厂输入图像执行二分类推理,用于判断机械臂夹爪是否夹紧。
类别定义:
0 → 夹具夹紧 (False)
1 → 夹具打开 (True)
rknn模型只加载一次复用全局实例提高推理效率。
## 调用示例
您可以直接调用 yolov11_cls_inference 函数,以便集成到其他项目中:
示例 1: 单张图片推理
```bash
from main_cls import yolov11_cls_inference
import cv2
# 读取图像
bgr_image = cv2.imread("11.jpg")
rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
# 调用推理函数
class_id, bool_value = yolov11_cls_inference(
model_path="yolov11_cls.rknn",
raw_image=rgb_image,
target_size=(640, 640)
)
print(f"类别ID: {class_id}, 布尔值: {bool_value}")
```
示例 2: 多次推理(复用模型)
```bash
from main_cls import init_rknn_model, yolov11_cls_inference_once
import cv2
# 初始化一次模型
rknn_model = init_rknn_model("cls_rk3568.rknn")
# 读取图像
bgr_image = cv2.imread("12.jpg")
rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
# 使用已加载模型进行推理
class_id, bool_value = yolov11_cls_inference_once(rknn_model, rgb_image)
if bool_value:
print("夹具夹紧")
else:
print("夹具打开")
```