bsw215583320
2025-04-27 631076f65bf9f2a039fca23073ddb6dc626fee07
refactor(herb_ai):优化图像识别和日志记录逻辑

- 降低图像清晰度判断阈值,从 200 调整为 150
- 优化安全检测识别结果的日志记录逻辑,仅在检测到结果时打印
-针对特定类别(shangliao 和 high)进行更有针对性的日志记录
- 移除了一些冗余的日志记录语句,提高日志的可读性和性能
已修改1个文件
9 ■■■■■ 文件已修改
openvino/herb_ai.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
openvino/herb_ai.py
@@ -16,7 +16,6 @@
from logger_config import logger
import threading
multiprocessing.freeze_support()
@@ -95,7 +94,7 @@
            logger.info(f"识别结果转换为保存图片名称:, {save_name2}")
            # 判断图像的清晰度
            # 保存调整尺寸后的图片
            if laplacian > 200:
            if laplacian > 150:
                c_ = save_path + "2/c/"
                if not os.path.exists(c_):
                    os.makedirs(c_)
@@ -223,6 +222,8 @@
                    det_res[class_name] = det_res[class_name] if det_res[class_name] > scores[i] else scores[i]
                else:
                    det_res[class_name] = scores[i]
        # 如果det_res不为空,则打印det_res
        if det_res != {}:
        print(det_res)
        logger.info(f"安全检测识别结果, {det_res}")
        # 如果cass_ids中包含0,则表示有安全检测到人体
@@ -246,8 +247,10 @@
        else:
            count += 1
        class_old = class_
        if class_ == "shangliao":
        print(f"{class_}:{count}: {max_probability}")
        logger.info(f"{class_}:{count}: {max_probability}")
        # 判断是否上料并且上料次数大于10次
        if class_ == "shangliao" and count > 10:
            status = "正在上料"
@@ -283,9 +286,9 @@
        predicted_class2 = np.argmax(probabilities2, axis=1)[0]
        max_probability2 = np.max(probabilities2, axis=1)[0]
        class_2 = hoister_position.class_names[predicted_class2]
        if class_2 == "high":
        print(f"-----------{class_2}:{predicted_class2}: {max_probability2}")
        logger.info(f"-----------{class_2}:{predicted_class2}: {max_probability2}")
        if predicted_class2 == 0:
            feeder_res = {class_2: max_probability2}
            class_feeder = "aifeeder," + f"{feeder_res}"