HIKIDMVS.cs
6.5 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using HalconDotNet;
using IDHIKCamera;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
namespace CodeLibrary.camera
{
public class HIKIDMVS : ClsCamera
{
static new string cameraName = null;
public override bool Load()
{
try
{
HDLogUtil.error("加载扫码相机:" );
IDHIK.Instance.Load();
List<string> names = IDHIK.Instance.cameraName;
_name = names.ToArray();
IDHIK.Instance.DrawLine = false;
HDLogUtil.error($"加载扫码相机:{string.Join(",", names)}");
if (names != null)
{
// hikNameList.AddRange(names);
//foreach (string name in names)
//{
// LogNet.log.Info("加载到IDHIK相机:" + name);
//}
cameraName = names.Find(s => s.Contains("ID"));
HDLogUtil.error("加载到扫码相机:" + cameraName);
}
}
catch (Exception ex)
{
HDLogUtil.error("解析IDHIK出错:" + ex.StackTrace);
return false;
}
return true;
}
public override bool Open(int index)
{
return IDHIK.Instance.Open(index);
}
public override bool Open(string name)
{
return IDHIK.Instance.Open(name);
}
public override bool OpenAll()
{
return IDHIK.Instance.OpenAll();
}
public override void Close(int index)
{
IDHIK.Instance.Close(index);
}
public override void Close(string name)
{
IDHIK.Instance.Close(name);
}
public override void CloseAll()
{
IDHIK.Instance.CloseAll();
}
public override HObject CaptureOnImage(string name, out List<CodeInfo> cc)
{
Bitmap bitmap = null;
cc = GetImageAndIdentifyCode(out bitmap);
return null;
}
public override HObject CaptureOnImage(string name, out Bitmap bmp,out List<CodeInfo> codeInfos, bool nohalcon = false)
{
codeInfos= GetImageAndIdentifyCode(out bmp);
return null;
}
public override Bitmap GrabOne(int index, PixelType pt = PixelType.MONO8)
{
Bitmap bitmap = null;
_ = GetImageAndIdentifyCode(out bitmap);
return bitmap;
}
public override Bitmap GrabOne(string name, PixelType pt = PixelType.MONO8)
{
Bitmap bitmap = null;
_ = GetImageAndIdentifyCode(out bitmap);
return bitmap;
}
public override Bitmap GrabOneImage(string name, PixelType pt = PixelType.MONO8)
{
Bitmap bitmap = null;
_ = GetImageAndIdentifyCode(out bitmap);
return bitmap;
}
public override bool ProcessOnImage(string name, out object[] result, params Func<string, Bitmap, object>[] func)
{
result = null;
return true;
}
static List<BarcodeInfo> grabOne(out Bitmap bitmap)
{
bitmap = null;
List<BarcodeInfo> barcodeInfos = new List<BarcodeInfo>();
if (string.IsNullOrEmpty(cameraName))
{
return barcodeInfos;
}
try
{
bitmap = (Bitmap)IDHIK.Instance.GrabOne(cameraName, out List<CodeInfo> cc);
if (cc != null)
{
cc.ForEach(c =>
{
barcodeInfos.Add(new BarcodeInfo()
{
Center = new PointF(c.X, c.Y),
Angle = (float)c.Orientation,
CodeType = c.CodeType,
Text = c.CodeStr
});
});
}
}
catch (Exception e)
{
HDLogUtil.error($"{cameraName}取图失败:{e}");
}
return barcodeInfos;
}
public override List<CodeInfo> GetImageAndIdentifyCode(out Bitmap bitmap)
{
bitmap = null;
List<CodeInfo> codeisc = new List<CodeInfo>();
HDLogUtil.error("获取图片相机名称:" + cameraName);
if (string.IsNullOrEmpty(cameraName))
{
return null;
}
try
{
List<CodeInfo> cod = new List<CodeInfo>();
bitmap = (Bitmap)IDHIK.Instance.GrabOne(cameraName, out cod);
cod.ForEach(c =>
{
codeisc.Add(new CodeInfo()
{
CodeStr=c.CodeStr,
CodeType=c.CodeType,
X = c.X,
Y = c.Y,
Orientation= c.Orientation,
});
});
}
catch (Exception e)
{
HDLogUtil.error($"{cameraName}取图失败:{e}");
}
return codeisc;
}
}
public class BarcodeInfo
{
//
// 摘要:
// 文本
public string Text { get; set; }
//
// 摘要:
// 条码类型
public string CodeType { get; set; }
//
// 摘要:
// 中心点
public PointF Center { get; set; }
//
// 摘要:
// 角度,3点钟方向0°,逆时针为正,顺时针为负。
public float Angle { get; set; }
//
// 摘要:
// 条码尺寸大小
public SizeF Size { get; set; }
//
// 摘要:
// 原点垂直于经过中心点的直线的距离
public float Distance { get; set; }
//
// 摘要:
// 副本,深拷贝
public BarcodeInfo Clone()
{
BarcodeInfo barcodeInfo = new BarcodeInfo();
PropertyInfo[] properties = barcodeInfo.GetType().GetProperties();
PropertyInfo[] properties2 = GetType().GetProperties();
for (int i = 0; i < properties.Length; i++)
{
properties[i].SetValue(barcodeInfo, properties2[i].GetValue(this));
}
return barcodeInfo;
}
}
}