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] +
opencv dnn +onnx模型 做推理
最新推荐文章于 2025-04-13 09:00:00 发布
该代码定义了一个名为`classdl_detection_model`的类,用于处理ONNX模型进行目标检测。初始化方法设置模型参数,包括置信度阈值等。`detectImage`方法执行模型推理,`postprocess`方法处理结果,包括NMS非极大抑制。此外,还有绘制检测框的辅助方法。

最低0.47元/天 解锁文章
5万+

被折叠的 条评论
为什么被折叠?



