图像检测识别物体不画框

Viewed 33

问题描述


训练的是图像检测,代码运行后可以正常实时拍摄画面也不报错,可是识别到目标物体后不画框也不标注

复现步骤


训练的是图像检测,代码运行后可以正常实时拍摄画面也不报错,可是识别到目标物体后不画框也不标注代码如下

# -*- coding: utf-8 -*-
import os, gc, sys, time
from libs.PlatTasks import DetectionApp
from libs.PipeLine import PipeLine
from libs.Utils import *

display_mode = "lcd"
rgb888p_size = [640, 480]
root_path = "/sdcard/mp_deployment_source/"

deploy_conf = read_json(root_path + "/deploy_config.json")
kmodel_path = root_path + deploy_conf["kmodel_path"]
labels = deploy_conf["categories"]
confidence_threshold = deploy_conf["confidence_threshold"]
nms_threshold = deploy_conf["nms_threshold"]
model_input_size = deploy_conf["img_size"]
model_type = deploy_conf["model_type"]

# 鲁棒性修改:确保 anchors 转换万无一失
anchors = []
if model_type == "AnchorBaseDet":
    try:
        # 尝试展开成一维列表 [33, 52, 69, ...]
        anchors = deploy_conf["anchors"][0] + deploy_conf["anchors"][1] + deploy_conf["anchors"][2]
    except:
        # 如果报错,直接传入原始结构
        anchors = deploy_conf["anchors"]

inference_mode = "video"
debug_mode = 0

os.exitpoint(os.EXITPOINT_ENABLE)

pl = PipeLine(rgb888p_size=rgb888p_size, display_mode=display_mode)
pl.create()
display_size = pl.get_display_size()

det_app = DetectionApp(inference_mode, kmodel_path, labels, model_input_size, anchors, model_type, confidence_threshold, nms_threshold, rgb888p_size, display_size, debug_mode=debug_mode)
det_app.config_preprocess()

try:
    while True:
        with ScopedTiming("total", 1):
            img = pl.get_frame()
            if img is None:
                continue

            if hasattr(pl, "osd_img") and pl.osd_img is not None:
                try:
                    pl.osd_img.clear()
                except:
                    pass

            res = det_app.run(img)

            # 重点观察这里!!
            if res:
                print("Detected successfully:", res)
            else:
                print("Nothing detected")

            det_app.draw_result(pl.osd_img, res)
            pl.show_image()
            gc.collect()
            os.exitpoint()

except KeyboardInterrupt as e:
    print("User stop", e)
except BaseException as e:
    print("Exception", e)

finally:
    try:
        det_app.deinit()
    except:
        pass
    try:
        pl.destroy()
    except:
        pass
    os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
    time.sleep_ms(100)

硬件板卡


K230D

软件版本


CanMV_K230D_ATK_DNK230D_micropython_v1.3-0-g8dd764f_nncase_v2.9.0.img

其他信息


控制台显示控制台显示上传中...

{
    "chip_type": "k230",
    "inference_width": 320,
    "inference_height": 320,
    "confidence_threshold": 0.15,
    "nms_threshold": 0.4,
    "nncase_version": "2.11.0",
    "model_type": "AnchorBaseDet",
    "img_size": [
        320,
        320
    ],
    "anchors": [
        [
            33,
            52,
            69,
            94,
            228,
            103
        ],
        [
            178,
            193,
            160,
            219,
            138,
            303
        ],
        [
            295,
            156,
            171,
            284,
            228,
            215
        ]
    ],
    "mean": [
        0.485,
        0.456,
        0.406
    ],
    "std": [
        0.229,
        0.224,
        0.225
    ],
    "categories": [
        "dimoo",
        "laptop",
        "cup"
    ],
    "nms_option": false,
    "kmodel_path": "best_AnchorBaseDet_can2_5_s_20260610112554.kmodel",
    "num_classes": 3
}
1 Answers

这是没事别到啊,返回结果这不都是空的吗