opencv dnn +onnx模型 做推理

该代码定义了一个名为`classdl_detection_model`的类,用于处理ONNX模型进行目标检测。初始化方法设置模型参数,包括置信度阈值等。`detectImage`方法执行模型推理,`postprocess`方法处理结果,包括NMS非极大抑制。此外,还有绘制检测框的辅助方法。
class dl_detection_model():
    def __init__(self, model, classNum, confile, confThreshold=0.3, nmsThreshold=0.3, objThreshold=0.5):
        try:
            # 模型初始设置
            self.net = cv2.dnn.readNetFromONNX(model)
            self.num_classes = classNum
            self.confile = confile
            self.confThreshold = confThreshold
            self.nmsThreshold = nmsThreshold
            self.objThreshold = objThreshold

            # 计算设置
            self.anchors = [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]]
            self.nl = len(self.anchors)
            self.no = self.num_classes + 5
            self.grid = [np.zeros(1)] * self.nl
            self.stride = np.array([8., 16., 32.])
            self.na = len(self.anchors[0]) // 2
            self.anchor_grid = np.asarray(self.anchors, dtype=np.float32).reshape(self.nl, 1, -1, 1, 1, 2)

            #输出元素
            self.outimg = 0
            self.outinfo = []

        except Exception as e:
            LOG.error('Nut recognize model building with exception: {
   
   }.'.format(str(e)))

    def create_detection(self, image):
        try:
            self.image = image

            # 绘图设置
            self.res_rect_size = int((self.image.shape[1] +
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值