轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-30 06c627ec032b3f3876fd7db8a3ff0ff1a6614fa2
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System.Collections;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
 
namespace LB_SmartVision
{
    public class ObservableConcurrentDictionary<TKey, TValue> : IDictionary<TKey, TValue>
    {
 
        public readonly ConcurrentDictionary<TKey, TValue> Items = new();
 
        public ICollection<TKey> Keys => ((IDictionary<TKey, TValue>)Items).Keys;
 
        public ICollection<TValue> Values => ((IDictionary<TKey, TValue>)Items).Values;
 
        public int Count => ((ICollection<KeyValuePair<TKey, TValue>>)Items).Count;
 
        public bool IsReadOnly => ((ICollection<KeyValuePair<TKey, TValue>>)Items).IsReadOnly;
 
        public event EventHandler<DictionaryChangedEventArgs<TKey, TValue>> DictionaryChanged;
 
        public TValue this[TKey key]
        {
            get
            {
                return Items.TryGetValue(key, out TValue Value) ? Value : default;
            }
            set
            {
                //bool exists = Items.TryGetValue(key, out TValue oldValue);
                if (Items.ContainsKey(key))
                    Items[key] = value;
                //if (exists)
                //    OnDictionaryChanged(DictionaryChangeType.Updated, key, key, value, oldValue);
            }
        }
 
        public bool TryAdd(TKey key, TValue value)
        {
            if (Items.ContainsKey(key))
            {
                Items[key] = value;
                return true;
            }
            if (Items.TryAdd(key, value))
            {
                OnDictionaryChanged(DictionaryChangeType.Added, key, key, value, value);
                return true;
            }
            return false;
        }
 
        public bool TryRemove(TKey key, out TValue value)
        {
            if (Items.TryRemove(key, out value))
            {
                OnDictionaryChanged(DictionaryChangeType.Removed, key, key, default, value);
                return true;
            }
            return false;
        }
 
        public bool TryRename(TKey oldKey, TKey newKey)
        {
            if (Items.TryRemove(oldKey, out TValue value))
            {
                Items.TryAdd(newKey, value);
                OnDictionaryChanged(DictionaryChangeType.Renamed, newKey, oldKey, value, value);
                return true;
            }
 
            return false;
        }
 
        protected virtual void OnDictionaryChanged(DictionaryChangeType changeType, TKey newKey, TKey oldKey, TValue newValue, TValue oldValue)
        {
            var handlers = DictionaryChanged;
            if (handlers != null)
            {
                foreach (EventHandler<DictionaryChangedEventArgs<TKey, TValue>> handler in handlers.GetInvocationList())
                {
                    try
                    {
                        handler(this, new DictionaryChangedEventArgs<TKey, TValue>(changeType, newKey, oldKey, newValue, oldValue));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"事件处理异常: {ex.Message}");
                    }
                }
            }
 
            //DictionaryChanged?.Invoke(this,
            //    new DictionaryChangedEventArgs<TKey, TValue>(changeType, newKey, oldKey, newValue, oldValue));
        }
 
        public void Add(TKey key, TValue value)
        {
            ((IDictionary<TKey, TValue>)Items).Add(key, value);
        }
 
        // 在类中添加类型检查
        private static readonly bool IsStringKey = typeof(TKey) == typeof(string);
 
        public bool ContainsKey(TKey key)
        {
            if (!IsStringKey || key == null)
                return ((IDictionary<TKey, TValue>)Items).ContainsKey(key);
 
            var searchKey = key as string;
            return ((IDictionary<TKey, TValue>)Items).Keys.Any(k =>
                string.Equals(k as string, searchKey, StringComparison.OrdinalIgnoreCase));
        }
 
        public bool Remove(TKey key)
        {
            return ((IDictionary<TKey, TValue>)Items).Remove(key);
        }
 
        public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
        {
            return ((IDictionary<TKey, TValue>)Items).TryGetValue(key, out value);
        }
 
        public void Add(KeyValuePair<TKey, TValue> item)
        {
            ((ICollection<KeyValuePair<TKey, TValue>>)Items).Add(item);
        }
 
        public void Clear()
        {
            foreach (var kvp in Items)
                OnDictionaryChanged(DictionaryChangeType.Removed, kvp.Key, kvp.Key, default, kvp.Value);
 
            ((ICollection<KeyValuePair<TKey, TValue>>)Items).Clear();
        }
 
        public bool Contains(KeyValuePair<TKey, TValue> item)
        {
            return ((ICollection<KeyValuePair<TKey, TValue>>)Items).Contains(item);
        }
 
        public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
        {
            ((ICollection<KeyValuePair<TKey, TValue>>)Items).CopyTo(array, arrayIndex);
        }
 
        public bool Remove(KeyValuePair<TKey, TValue> item)
        {
            return ((ICollection<KeyValuePair<TKey, TValue>>)Items).Remove(item);
        }
 
        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            return ((IEnumerable<KeyValuePair<TKey, TValue>>)Items).GetEnumerator();
        }
 
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)Items).GetEnumerator();
        }
 
        // 实现其他IDictionary成员...
    }
 
    public enum DictionaryChangeType { Added, Removed, Renamed, Updated }
 
    public class DictionaryChangedEventArgs<TKey, TValue> : EventArgs
    {
        public DictionaryChangeType ChangeType { get; }
        public TKey NewKey { get; }
        public TKey OldKey { get; }
        public TValue NewValue { get; }
        public TValue OldValue { get; }
 
        public DictionaryChangedEventArgs(DictionaryChangeType changeType, TKey newKey, TKey oldKey, TValue newValue, TValue oldValue)
        {
            ChangeType = changeType;
            NewKey = newKey;
            OldKey = oldKey;
            NewValue = newValue;
            OldValue = oldValue;
        }
    }
}