修改框架(未完全完成)实现单个相机分开绑定算法

This commit is contained in:
2025-10-20 17:47:48 +08:00
parent 31d9f8d6b6
commit 73249ee6c2
11 changed files with 1226 additions and 422 deletions

View File

@@ -31,40 +31,41 @@ namespace Check.Main.Infer
if (modelSettings == null) return;
ThreadSafeLogger.Log("开始加载YOLO模型...");
foreach (var setting in modelSettings)
// 筛选出启用的深度学习模型进行加载
foreach (var setting in modelSettings.Where(s => s.IsEnabled && s.M_AType == AlgorithmType.DeepLearning))
{
bool gpuUse = false;
if (setting.CheckDevice == DetectDevice.GPU)
{
gpuUse = true;
}
bool gpuUse = setting.CheckDevice == DetectDevice.GPU;
if (string.IsNullOrEmpty(setting.Path) || !File.Exists(setting.Path))
{
ThreadSafeLogger.Log($"[警告] 模型 '{setting.Name}' (ID: {setting.Id}) 路径无效或文件不存在,已跳过加载。");
ThreadSafeLogger.Log($"[警告] YOLO模型 '{setting.Name}' (ID: {setting.Id}) 路径无效或文件不存在,已跳过加载。");
continue;
}
try
{
// 创建YOLO实例
var yolo = new Yolo(new YoloOptions
{
OnnxModel = setting.Path,
// 您可以根据需要从配置中读取这些值
ModelType = (YoloDotNet.Enums.ModelType)setting.MType,
Cuda = gpuUse, // 推荐使用GPU
PrimeGpu = false
Cuda = gpuUse,
//Confidence = setting.YoloConfidenceThreshold, // 从 ModelSettings 读取
//Nms = setting.YoloNmsThreshold, // 从 ModelSettings 读取
PrimeGpu = false // 根据需求设置
});
// 保存阈值配置
var conf = setting.YoloConfidenceThreshold;
var nms = setting.YoloNmsThreshold;
if (_loadedModels.TryAdd(setting.Id, yolo))
{
ThreadSafeLogger.Log($"成功加载模型 '{setting.Name}' (ID: {setting.Id})。");
ThreadSafeLogger.Log($"成功加载YOLO模型 '{setting.Name}' (ID: {setting.Id})。");
}
}
catch (Exception ex)
{
ThreadSafeLogger.Log($"[错误] 加载模型 '{setting.Name}' (ID: {setting.Id}) 失败: {ex.Message}");
ThreadSafeLogger.Log($"[错误] 加载YOLO模型 '{setting.Name}' (ID: {setting.Id}) 失败: {ex.Message}");
}
}
ThreadSafeLogger.Log($"YOLO模型加载完成共成功加载 {_loadedModels.Count} 个模型。");