BoxEquip_AutoFindPos.cs
25.4 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
using CodeLibrary;
using HuichuanLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using static eyemLib_Sharp.EyemLibDemo;
namespace OnlineStore.DeviceLibrary
{
public partial class BoxEquip
{
//public Dictionary<string, List<DrawerInfo>> DrawerNums = new Dictionary<string, List<DrawerInfo>>();
public AutoFindPos autoFindPos;
public bool autoFindPosMode = false;
private void InitDrawInfos()
{
autoFindPos = new AutoFindPos(Config);
//DrawerNums.Add("A", new List<DrawerInfo>());
//DrawerNums.Add("B", new List<DrawerInfo>());
//List<DrawerPosition> drawerPositions = CSVPositionReader<DrawerPosition>.getPositionList();
//foreach (DrawerPosition position in drawerPositions)
//{
// if (position.StoreId.Equals(DeviceID))
// {
// DrawerNums[PosSide(position.PositionNum)].Add(new DrawerInfo(position.PositionNum,PositionNumList));
// }
//}
}
/// <summary>
/// 获取抽屉/仓位所在面
/// </summary>
/// <param name="pos">位置</param>
/// <returns></returns>
private string PosSide(string pos)
{
if (pos.Substring(2, 2).Equals("AA")) return "A";
else if (pos.Substring(2, 2).Equals("BB")) return "B";
return "";
}
/// <summary>
/// 获取抽屉/仓位所在面的相机序号
/// </summary>
/// <param name="pos">位置</param>
/// <returns></returns>
private string CamPosSide(string pos)
{
if (pos.Substring(2, 2).Equals("AA")) return "box_A";
else if (pos.Substring(2, 2).Equals("BB")) return "box_B";
return "box_A";
}
/// <summary>
/// 获取轴的负限位
/// </summary>
/// <param name="axisNo"></param>
/// <returns></returns>
public bool GetAxisNelSts(short axisNo)
{
AxisSts sts = HCBoardManager.GetAxisSts(axisNo);
return sts.NEL == 1;
}
/// <summary>
/// 获取轴的正限位
/// </summary>
/// <param name="axisNo"></param>
/// <returns></returns>
public bool GetAxisPelSts(short axisNo)
{
AxisSts sts = HCBoardManager.GetAxisSts(axisNo);
return sts.PEL == 1;
}
private void ToDrawer_StartPoint()
{
StringBuilder stringBuilder = new StringBuilder(MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 4));
stringBuilder.Append(autoFindPos.CurRow.ToString().PadLeft(2, '0'));
stringBuilder.Append(autoFindPos.CurColumn.ToString().PadLeft(2, '0'));
stringBuilder.Append("0101");
if (MoveInfo.MoveParam.PosInfo.PosId.Equals(stringBuilder.ToString()))
{
MoveAxisToP3();
UpdownAxisTo_P6_P12();
PullAxis_UpdownToLowP4();
}
else
{
autoFindPos.Startposition_MoveAxis = MoveAxis.GetAclPosition();
autoFindPos.Startposition_PullUpdpwnAxis = PullAxis_Updown.GetAclPosition();
autoFindPos.Startposition_UpDownAxis = UpdownAxis.GetAclPosition();
LogUtil.info($"视觉对位 运行到抽屉 行={autoFindPos.CurRow},列={autoFindPos.CurColumn}");
MoveAxis.AbsMove(MoveInfo, autoFindPos.Startposition_MoveAxis + (autoFindPos.CurColumn - autoFindPos.PreColumn) * autoFindPos.Row_Spacing, Config.MoveAxis_P1_Speed);
UpdownAxis.AbsMove(MoveInfo, autoFindPos.Startposition_UpDownAxis + (autoFindPos.CurRow - autoFindPos.PreRow) * autoFindPos.Column_Spacing, Config.Updown_P1_Speed);
PullAxis_Updown.AbsMove(MoveInfo, autoFindPos.Startposition_PullUpdpwnAxis + (autoFindPos.CurRow - autoFindPos.PreRow) * autoFindPos.Column_Spacing, Config.PullAxis_Updown_P1_Speed);
}
}
private bool CheckMarkXPoint(EyemOcsFXYR eyemOcsFXYR)
{
if (Math.Abs(Config.Drawer_X - eyemOcsFXYR.fX) < Config.Drawer_X_Error)
{
LogInfo($"视觉对位 {MoveInfo.SLog}:Mark点X轴坐标{eyemOcsFXYR.fX},模板Mark点X轴坐标{Config.Drawer_X},X轴偏差{(Config.Drawer_X - eyemOcsFXYR.fX)},在误差范围内" +
$"[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
AutoFindPosSaveImage($"OK_Mark点X轴坐标{eyemOcsFXYR.fX},模板Mark点X轴坐标{Config.Drawer_X},X轴偏差{(Config.Drawer_X - eyemOcsFXYR.fX)}");
return true;
}
AutoFindPosSaveImage($"NG_Mark点X轴坐标{eyemOcsFXYR.fX},模板Mark点X轴坐标{Config.Drawer_X},X轴偏差{(Config.Drawer_X - eyemOcsFXYR.fX)}");
LogInfo($"视觉对位 {MoveInfo.SLog}:Mark点X轴坐标{eyemOcsFXYR.fX},模板Mark点X轴坐标{Config.Drawer_X},X轴偏差{(Config.Drawer_X - eyemOcsFXYR.fX)}," +
$"行走机构相对移动{(Config.Drawer_X - eyemOcsFXYR.fX) * autoFindPos.XCoeffOfCoorToPulse}[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
MoveAxis.AbsMove(MoveInfo, Convert.ToInt32(MoveAxis.GetAclPosition() + (Config.Drawer_X - eyemOcsFXYR.fX) * autoFindPos.XCoeffOfCoorToPulse), Config.MoveAxis_P1_Speed / 2);
return false;
}
private bool CheckMarkYPoint(EyemOcsFXYR eyemOcsFXYR)
{
if (Math.Abs(Config.Drawer_Y - eyemOcsFXYR.fY) < Config.Drawer_Y_Error)
{
LogInfo($"视觉对位 {MoveInfo.SLog}:Mark点Y轴坐标{eyemOcsFXYR.fY},模板Mark点Y轴坐标{Config.Drawer_Y},Y轴偏差{(Config.Drawer_Y - eyemOcsFXYR.fY)},在误差范围内" +
$"[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
AutoFindPosSaveImage($"OK_Mark点Y轴坐标{eyemOcsFXYR.fY},模板Mark点Y轴坐标{Config.Drawer_Y},Y轴偏差{(Config.Drawer_Y - eyemOcsFXYR.fY)}");
return true;
}
AutoFindPosSaveImage($"NG_Mark点Y轴坐标{eyemOcsFXYR.fY},模板Mark点Y轴坐标{Config.Drawer_Y},Y轴偏差{(Config.Drawer_Y - eyemOcsFXYR.fY)}");
UpdownAxis.AbsMove(MoveInfo, Convert.ToInt32(UpdownAxis.GetAclPosition() + (Config.Drawer_Y - eyemOcsFXYR.fY) * autoFindPos.YCoeffOfCoorToPulse), Config.Updown_P1_Speed / 2);
PullAxis_Updown.AbsMove(MoveInfo, Convert.ToInt32(PullAxis_Updown.GetAclPosition() + (Config.Drawer_Y - eyemOcsFXYR.fY) * autoFindPos.YCoeffOfCoorToPulse), Config.Updown_P1_Speed / 2);
LogInfo($"视觉对位 {MoveInfo.SLog}:Mark点Y轴坐标{eyemOcsFXYR.fY},模板Mark点Y轴坐标{Config.Drawer_Y},Y轴偏差{(Config.Drawer_Y - eyemOcsFXYR.fY)}," +
$"移栽升降轴、料屉升降轴相对移动{(Config.Drawer_Y - eyemOcsFXYR.fY) * autoFindPos.YCoeffOfCoorToPulse}[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
return false;
}
private void AutoFindPosSaveImage(string imgInfo)
{
//SaveImage(CamPosSide(MoveInfo.MoveParam.PosInfo.PosId), $"{MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 4)}", $"{DateTime.Now.ToString("yyyyMMddhhmmss")}_{autoFindPos.CurRow}_{autoFindPos.CurColumn}_{imgInfo}");
}
public void StartFindPos(InOutParam param)
{
if (isInSuddenDown || isNoAirpressure_Check ||
(!runStatus.Equals(RunStatus.Runing))
|| (!MoveInfo.MoveType.Equals(MoveType.None)))
{
LogUtil.error(Name + " 启动视觉对位出错,忙碌或报警中 ,storeStatus=" + runStatus + ",MoveType=" + MoveInfo.MoveType + ",isInSuddenDown=" + isInSuddenDown + ",isNoAirpressure_Check=" + isNoAirpressure_Check);
return;
}
LogInfo(" 启动视觉对位【" + param.PosInfo.ToStr() + "】 ");
param.MoveP = new LineMoveP(Config, param.PosInfo.PosId);
MoveInfo.NewMove(MoveType.Working, param);
SetBoxStatus(DeviceStatus.Debugging, RunStatus.Busy);
MoveInfo.NextMoveStep(StepEnum.SA_01_Pos_Start_Find_Pos);
PullAxis_Inout_To_P1();
}
private bool SaveDrawerPosition()
{
StringBuilder stringBuilder = new StringBuilder(MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 4));
stringBuilder.Append(autoFindPos.CurRow.ToString().PadLeft(2, '0'));
stringBuilder.Append(autoFindPos.CurColumn.ToString().PadLeft(2, '0'));
List<string> curDrawer = PositionNumList.FindAll(s => s.StartsWith(stringBuilder.ToString()));
if (curDrawer != null && curDrawer.Count > 0)
{
foreach (string item in curDrawer)
{
BoxPosition ktkPosition = CSVPositionReader<BoxPosition>.GetPositon(item);
if (ktkPosition != null)
{
ktkPosition.MoveAxis_P3 = MoveAxis.GetAclPosition();
ktkPosition.Updown_P6_P12 = UpdownAxis.GetAclPosition();
ktkPosition.Updown_P7_P13 = UpdownAxis.GetAclPosition() + autoFindPos.UpdownAxis_Diff_Upper_Low;
ktkPosition.PullAxis_Updown_P4 = PullAxis_Updown.GetAclPosition();
ktkPosition.PullAxis_Updown_P2 = PullAxis_Updown.GetAclPosition() + autoFindPos.PullUpdown_Diff_mid;
ktkPosition.PullAxis_Updown_P3 = PullAxis_Updown.GetAclPosition() + autoFindPos.PullUpdown_Diff_high;
}
//位置配置
string appPath = Application.StartupPath;
//如果总配置文件存在,保存到总的配置文件
string positionConfigFile = appPath + ConfigAppSettings.GetValue(Setting_Init.ConfigPath_BoxPosition);
if (!File.Exists(positionConfigFile))
{
string nameStr = DeviceID.ToString();
positionConfigFile = positionConfigFile.Replace(".csv", "_" + nameStr + ".csv");
}
bool result = CSVPositionReader<BoxPosition>.SavePostion(positionConfigFile, ktkPosition);
if (!result)
{
SetWarnMsg("库位【" + item + "】保存失败!");
}
else
{
// LogInfo($"存储机构-视觉对位 {MoveInfo.SLog}:库位[{item}]保存成功[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
}
}
LogInfo($"视觉对位 {MoveInfo.SLog}:抽屉[{autoFindPos.CurRow},{autoFindPos.CurColumn}]位置信息保存成功[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
return true;
}
return false;
}
public void FindPosEnd()
{
MoveInfo.EndMove();
SetBoxStatus(DeviceStatus.Debugging, RunStatus.Runing);
if (MoveInfo.MoveParam != null)
LogInfo($"视觉对位 {MoveInfo.SLog}:对位结束[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
foreach (string item in autoFindPos.FailedDrawers)
{
LogUtil.info("视觉对位失败抽屉:" + item);
}
}
EyemOcsFXYR ocsFXYR;
public void AutoFindPosProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
if (!autoFindPosMode)
return;
switch (MoveInfo.MoveStep)
{
case StepEnum.SA_01_Pos_Start_Find_Pos:
MoveInfo.NextMoveStep(StepEnum.SA_02_Pos_To_Drawer_StartPoint);
LogInfo($"视觉对位 {MoveInfo.SLog}:到抽屉起始点," +
$"行走机构到抽屉起始点,移栽升降轴到抽屉起始点[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
ToDrawer_StartPoint();
break;
case StepEnum.SA_02_Pos_To_Drawer_StartPoint:
//取图
//Bitmap bitmap = null;
Bitmap bitmap = AcqImage(CamPosSide(MoveInfo.MoveParam.PosInfo.PosId));
int res = AutoFindPos.GetMarkInfo(bitmap, $"{MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 4)}",$"row{autoFindPos.CurRow}_col{autoFindPos.CurColumn}", out ocsFXYR);
if (res == 0)
{
MoveInfo.NextMoveStep(StepEnum.SA_03_Pos_AcqImg);
LogInfo($"视觉对位 {MoveInfo.SLog}:取图[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
}
else if (res == -4)
{
SetWarnMsg($"视觉对位异常[code={res}],未找到Mark点。对位失败的行={autoFindPos.CurRow}[{MoveAxis.GetAclPosition()}],列={autoFindPos.CurColumn}[{UpdownAxis.GetAclPosition()}]");
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
MoveInfo.NextMoveStep(StepEnum.SA_05_Pos_NextDrawer);
}
else
{
SetWarnMsg($"视觉对位异常[code={res}],未找到Mark点。对位失败的行={autoFindPos.CurRow}[{MoveAxis.GetAclPosition()}],列={autoFindPos.CurColumn}[{UpdownAxis.GetAclPosition()}]");
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
MoveInfo.NextMoveStep(StepEnum.SA_05_Pos_NextDrawer);
}
break;
case StepEnum.SA_03_Pos_AcqImg:
if (CheckMarkXPoint(ocsFXYR) && CheckMarkYPoint(ocsFXYR))
{
//存储抽屉位置信息
if (SaveDrawerPosition())
{
}
else
{
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
}
MoveInfo.NextMoveStep(StepEnum.SA_05_Pos_NextDrawer);
}
else
{
MoveInfo.NextMoveStep(StepEnum.SA_04_Pos_AdjPos);
}
break;
case StepEnum.SA_04_Pos_AdjPos:
MoveInfo.NextMoveStep(StepEnum.SA_02_Pos_To_Drawer_StartPoint);
break;
case StepEnum.SA_05_Pos_NextDrawer:
if (autoFindPos.CurColumn < autoFindPos.Columns)
{
MoveInfo.NextMoveStep(StepEnum.SA_01_Pos_Start_Find_Pos);
autoFindPos.PreColumn = autoFindPos.CurColumn;
autoFindPos.PreRow = autoFindPos.CurRow;
autoFindPos.CurColumn++;
}
else
{
if (autoFindPos.CurRow < autoFindPos.Rows)
{
MoveInfo.NextMoveStep(StepEnum.SA_06_Neg_Start_Find_Pos);
autoFindPos.PreRow = autoFindPos.CurRow;
autoFindPos.CurRow++;
autoFindPos.PreColumn = autoFindPos.CurColumn;
}
else//结束
{
FindPosEnd();
}
}
break;
case StepEnum.SA_06_Neg_Start_Find_Pos:
MoveInfo.NextMoveStep(StepEnum.SA_07_Neg_To_Drawer_StartPoint);
LogInfo($"视觉对位 {MoveInfo.SLog}:到抽屉起始点," +
$"行走机构到抽屉起始点,移栽升降轴到抽屉起始点[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
ToDrawer_StartPoint();
break;
case StepEnum.SA_07_Neg_To_Drawer_StartPoint:
//取图
//Bitmap bitmap1 = null;
Bitmap bitmap1 = AcqImage(CamPosSide(MoveInfo.MoveParam.PosInfo.PosId));
int res1 = AutoFindPos.GetMarkInfo(bitmap1, $"{MoveInfo.MoveParam.PosInfo.PosId.Substring(0, 4)}", $"row{autoFindPos.CurRow}_col{autoFindPos.CurColumn}", out ocsFXYR);
if (res1 == 0)
{
MoveInfo.NextMoveStep(StepEnum.SA_08_Neg_AcqImg);
LogInfo($"视觉对位 {MoveInfo.SLog}:取图[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
}
else if (res1 == -4)
{
SetWarnMsg($"视觉对位异常[code={res1}],未找到Mark点。对位失败的行={autoFindPos.CurRow}[{MoveAxis.GetAclPosition()}],列={autoFindPos.CurColumn}[{UpdownAxis.GetAclPosition()}]");
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
MoveInfo.NextMoveStep(StepEnum.SA_10_Neg_NextDrawer);
}
else
{
SetWarnMsg($"视觉对位异常[code={res1}],未找到Mark点。对位失败的行={autoFindPos.CurRow}[{MoveAxis.GetAclPosition()}],列={autoFindPos.CurColumn}[{UpdownAxis.GetAclPosition()}]");
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
MoveInfo.NextMoveStep(StepEnum.SA_10_Neg_NextDrawer);
}
break;
case StepEnum.SA_08_Neg_AcqImg:
if (CheckMarkXPoint(ocsFXYR) && CheckMarkYPoint(ocsFXYR))
{
//存储抽屉位置信息
if (SaveDrawerPosition())
{
}
else
{
autoFindPos.FailedDrawers.Add($"{autoFindPos.CurRow},{autoFindPos.CurColumn}");
}
MoveInfo.NextMoveStep(StepEnum.SA_10_Neg_NextDrawer);
}
else
{
MoveInfo.NextMoveStep(StepEnum.SA_09_Neg_AdjPos);
}
break;
case StepEnum.SA_09_Neg_AdjPos:
MoveInfo.NextMoveStep(StepEnum.SA_07_Neg_To_Drawer_StartPoint);
break;
case StepEnum.SA_10_Neg_NextDrawer:
if (autoFindPos.CurColumn > 1)
{
MoveInfo.NextMoveStep(StepEnum.SA_06_Neg_Start_Find_Pos);
autoFindPos.PreRow = autoFindPos.CurRow;
autoFindPos.PreColumn = autoFindPos.CurColumn;
autoFindPos.CurColumn--;
}
else
{
if (autoFindPos.CurRow < autoFindPos.Rows)
{
MoveInfo.NextMoveStep(StepEnum.SA_01_Pos_Start_Find_Pos);
autoFindPos.PreRow = autoFindPos.CurRow;
autoFindPos.CurRow++;
autoFindPos.PreColumn = autoFindPos.CurColumn;
}
else//结束
{
FindPosEnd();
}
}
break;
}
}
}
public class AutoFindPos
{
public int Startposition_MoveAxis { get; set; }
public int Startposition_UpDownAxis { get; set; }
public int Startposition_PullUpdpwnAxis { get; set; }
/// <summary>
/// 当前行
/// </summary>
public int CurRow { get; set; } = 1;
public int PreRow { get; set; } = 1;
/// <summary>
/// x坐标到脉冲的转换系数
/// </summary>
public float XCoeffOfCoorToPulse { get; set; } = 1;
/// <summary>
/// 坐标到脉冲的转换系数
/// </summary>
public float YCoeffOfCoorToPulse { get; set; } = 1;
/// <summary>
/// 当前列
/// </summary>
public int CurColumn { get; set; } = 1;
public int PreColumn { get; set; } = 1;
/// <summary>
/// 抽屉行数
/// </summary>
public int Rows { get; private set; }
/// <summary>
/// 抽屉列数
/// </summary>
public int Columns { get; private set; }
/// <summary>
/// 抽屉间行间距
/// </summary>
public int Row_Spacing { get; private set; }
/// <summary>
/// 抽屉间列间距
/// </summary>
public int Column_Spacing { get; private set; }
/// <summary>
/// 料屉中点与低点的差
/// </summary>
public int PullUpdown_Diff_mid { get; set; }
/// <summary>
/// 料屉高点与低点的差
/// </summary>
public int PullUpdown_Diff_high { get; set; }
/// <summary>
/// 移栽升降P13-P12的差
/// </summary>
public int UpdownAxis_Diff_Upper_Low { get; set; }
public int RowsInDraw { get; set; }
public int ColumnsInDraw { get; set; }
public List<string> FailedDrawers { get; set; }
BoxEquip_Config boxEquip_Config;
public AutoFindPos(BoxEquip_Config boxEquip_Config)
{
this.boxEquip_Config = boxEquip_Config;
Row_Spacing = boxEquip_Config.Row_Spacing;
Column_Spacing = boxEquip_Config.Column_Spacing;
Rows = boxEquip_Config.Drawer_Rows;
Columns = boxEquip_Config.Drawer_Columns;
FailedDrawers = new List<string>();
}
public void SetParam(int curRow, int curColumn, float xCooef, float yCooef)
{
CurRow = curRow;
CurColumn = curColumn;
PreColumn = curColumn;
PreRow = curRow;
Row_Spacing = boxEquip_Config.Row_Spacing;
Column_Spacing = boxEquip_Config.Column_Spacing;
Rows = boxEquip_Config.Drawer_Rows;
Columns = boxEquip_Config.Drawer_Columns;
XCoeffOfCoorToPulse = xCooef;
YCoeffOfCoorToPulse = yCooef;
}
/// <summary>
/// Mark点坐标信息
/// </summary>
/// <param name="bitmap">输入图片</param>
/// <param name="markCoor">mark点坐标信息</param>
/// <returns>0 正常 -4未定位到 </returns>
public static int GetMarkInfo(Bitmap bitmap,string subpath,string filename, out EyemOcsFXYR markCoor,out Bitmap resBitmap)
{
int flag;
markCoor = new EyemOcsFXYR();
EyemImage tpDstImg;
EyemImage image = eyemCvtToEyemImage(bitmap);
flag = eyemMarkerTracing(image, 120, ref markCoor, out tpDstImg);
string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.ImagePath) + subpath+"\\"+DateTime.Now.ToString("yyyyMMdd");
string path1 = path + "\\" + "Src\\";
string path2 = path + "\\" + "ResOut\\";
if (!System.IO.Directory.Exists(path1))
Directory.CreateDirectory(path1);
if (!System.IO.Directory.Exists(path2))
Directory.CreateDirectory(path2);
bitmap.Save(path1+filename+".bmp",System.Drawing.Imaging.ImageFormat.Bmp);
resBitmap = eyemCvtToBitmap(tpDstImg);
if (resBitmap != null)
{
resBitmap.Save(string.Format("{0}{1}_{2}_{3}_{4}.bmp",path2,filename, markCoor.fX, markCoor.fY, markCoor.fR));
}
Marshal.FreeHGlobal(image.vpImage);
eyemImageFree(ref tpDstImg);
return flag;
}
public static int GetMarkInfo(Bitmap bitmap, string subpath, string filename, out EyemOcsFXYR markCoor)
{
int flag;
markCoor = new EyemOcsFXYR();
EyemImage tpDstImg;
EyemImage image = eyemCvtToEyemImage(bitmap);
flag = eyemMarkerTracing(image, 120, ref markCoor, out tpDstImg);
string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.ImagePath) + subpath + "\\" + DateTime.Now.ToString("yyyyMMdd");
string path1 = path + "\\" + "Src\\";
string path2 = path + "\\" + "ResOut\\";
if (!System.IO.Directory.Exists(path1))
Directory.CreateDirectory(path1);
if (!System.IO.Directory.Exists(path2))
Directory.CreateDirectory(path2);
bitmap.Save(path1 + filename + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
Bitmap resBitmap = eyemCvtToBitmap(tpDstImg);
if (resBitmap != null)
{
resBitmap.Save(string.Format("{0}{1}_{2}_{3}_{4}.bmp", path2, filename, markCoor.fX, markCoor.fY, markCoor.fR));
}
Marshal.FreeHGlobal(image.vpImage);
eyemImageFree(ref tpDstImg);
return flag;
}
}
}