轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-31 ed2cb324d534291a221bb5a8cabe8ff48b3a46f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json;
using System.Collections.Concurrent;
 
namespace LB_VisionFlowNode
{
    // 序列化管理类
    public static class FlowSerializer
    {
        public static string Serialize(ConcurrentDictionary<string, FlowNode> nodes
            , ConcurrentDictionary<string, FlowConnection> connections)
        {
            var data = new FlowData
            {
                Nodes = nodes,
                Connections = connections
            };
 
            var settings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
 
            };
 
            return JsonConvert.SerializeObject(data, settings);
        }
 
        public static (ConcurrentDictionary<string, FlowNode>, ConcurrentDictionary<string, FlowConnection>) Deserialize(string json)
        {
            var settings = new JsonSerializerSettings { };
 
            var data = JsonConvert.DeserializeObject<FlowData>(json, settings);
            var nodeDictionary = data.Nodes.ToDictionary(n => n.Value.Id);
 
            // 重建连接关系
            foreach (var connection in data.Connections)
            {
                if (nodeDictionary.TryGetValue(connection.Value.StartNodeId, out var startNode))
                    connection.Value.StartNode = startNode.Value;
 
                if (nodeDictionary.TryGetValue(connection.Value.EndNodeId, out var endNode))
                    connection.Value.EndNode = endNode.Value;
            }
 
            //// 重建 NextNode 关系
            //foreach (var node in data.Nodes)
            //{
            //    foreach (var branchNodeName in node.Value.BranchNodes.Values)
            //    {
            //        if (!string.IsNullOrEmpty(branchNodeName) &&
            //                nodeDictionary.TryGetValue(branchNodeName, out var nextNode))
            //        {
            //            node.Value.NextNode = nextNode.Value;
            //        }
            //    }
            //}
 
            return (data.Nodes, data.Connections);
        }
    }
 
    // 包装类用于序列化
    public class FlowData
    {
        [JsonProperty("Nodes")]
        public ConcurrentDictionary<string, FlowNode> Nodes { get; set; }
            = new ConcurrentDictionary<string, FlowNode>();
 
        [JsonProperty("Connections")]
        public ConcurrentDictionary<string, FlowConnection> Connections { get; set; }
            = new ConcurrentDictionary<string, FlowConnection>();
    }
}