修改标签
This commit is contained in:
parent
8619d8ba2e
commit
fb1ae0bb08
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using AntdUI;
|
||||
using DH.Commons.Base;
|
||||
using DH.Commons.Models;
|
||||
|
||||
@ -88,6 +90,11 @@ namespace DH.Commons.Helper
|
||||
Directory.CreateDirectory(CurrentBackupDir);
|
||||
File.Copy(CurrentConfigPath, backupPath);
|
||||
}
|
||||
//重置标签文件路径和内容
|
||||
ConfigModel.DetectionList.ForEach(config =>
|
||||
{
|
||||
GenerateLabelFile(config);
|
||||
});
|
||||
|
||||
// 序列化当前配置
|
||||
var json = JsonSerializer.Serialize(new
|
||||
@ -100,7 +107,39 @@ namespace DH.Commons.Helper
|
||||
// 写入新配置
|
||||
File.WriteAllText(CurrentConfigPath, json);
|
||||
}
|
||||
private static void GenerateLabelFile(DetectionConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (config.DetectionLableList == null || string.IsNullOrEmpty(config.In_lable_path))
|
||||
return;
|
||||
|
||||
// 确保目录存在
|
||||
var directory = Path.GetDirectoryName(config.In_lable_path);
|
||||
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
// 写入文件内容
|
||||
using (var writer = new StreamWriter(config.In_lable_path, false))
|
||||
{
|
||||
foreach (var label in config.DetectionLableList)
|
||||
{
|
||||
// 根据实际需求格式化输出
|
||||
writer.WriteLine(label.LabelName.ToString()); // 假设DetectionLable重写了ToString()
|
||||
|
||||
// 或者明确指定格式:
|
||||
// writer.WriteLine($"{label.Id},{label.Name},{label.Confidence}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"生成标签文件失败: {ex.Message}");
|
||||
// 可以考虑记录更详细的日志
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 加载当前方案配置
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user