|
|
|
@@ -98,6 +98,10 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
/// </summary>
|
|
|
|
private int CurrPoinntCount = 0;
|
|
|
|
/// <summary>
|
|
|
|
/// 尺寸检测是否自动曝光完成
|
|
|
|
/// </summary>
|
|
|
|
private bool HaveAutoExp = false;
|
|
|
|
/// <summary>
|
|
|
|
/// 总计时
|
|
|
|
/// </summary>
|
|
|
|
private Stopwatch stopWatch;
|
|
|
|
@@ -2069,6 +2073,7 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
_isAuto = false;
|
|
|
|
CurrProcessIndex = -1;
|
|
|
|
CurrPoinntCount = 0;
|
|
|
|
HaveAutoExp = false;
|
|
|
|
CurrStepResult = 0;
|
|
|
|
IsGetStartSig = false;
|
|
|
|
|
|
|
|
@@ -2276,7 +2281,7 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string[] array = Directory.GetFiles(dirPath, "(*.bmp|*.jpg|*.log|*.json)");
|
|
|
|
string[] array = Directory.GetFiles(dirPath, "*.bmp;*.jpg;*.log;*.json");
|
|
|
|
foreach (string text in array)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
@@ -2296,7 +2301,7 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
array = Directory.GetFiles(dirPath, "(*.bmp|*.jpg|*.log|*.json)");
|
|
|
|
array = Directory.GetFiles(dirPath, "(*.bmp;*.jpg;*.log;*.json)");
|
|
|
|
foreach (string text in array)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
@@ -2615,6 +2620,7 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
IsGetStartSig = false;
|
|
|
|
CurrProcessIndex = 0;
|
|
|
|
CurrPoinntCount = 0;
|
|
|
|
HaveAutoExp = false;
|
|
|
|
CurrStepResult = 0;
|
|
|
|
LedRun();
|
|
|
|
stopWatch = new Stopwatch();
|
|
|
|
@@ -5746,13 +5752,11 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
Log($"{stepIndex + 1}-{processName}", $"轴组运行完成");
|
|
|
|
Thread.Sleep(markParam.WaitTime);
|
|
|
|
//自动聚焦?
|
|
|
|
if (markParam.MarkType == MarkCam.尺寸检测Mark)
|
|
|
|
if ((this.CurrPoinntCount == 0)&&(IsAutoFocus)&& (markParam.MarkType == MarkCam.尺寸检测Mark))
|
|
|
|
{
|
|
|
|
//尺寸在自动聚焦之前需要现使用曝光值
|
|
|
|
CamDevFront.SetExposure(markParam.ExposureTime);
|
|
|
|
CamDevFront.SetGain(markParam.Gain);
|
|
|
|
}
|
|
|
|
if ((this.CurrPoinntCount == 0)&&(IsAutoFocus)&& (markParam.MarkType == MarkCam.尺寸检测Mark))
|
|
|
|
{
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动聚焦...");
|
|
|
|
if(!AutoFocus(FocusStep, DirStep, DirWaitTime, FocusTimeOut))
|
|
|
|
{
|
|
|
|
@@ -5766,6 +5770,22 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
|
|
|
|
if (markParam.MarkType == MarkCam.尺寸检测Mark)
|
|
|
|
{
|
|
|
|
//完成聚焦之后使用自动曝光
|
|
|
|
if(markParam.AutoExposure)
|
|
|
|
{
|
|
|
|
if (AutoExposureF())
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
|
|
|
|
return stepIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CamDevFront.SetExposure(markParam.ExposureTime);
|
|
|
|
CamDevFront.SetGain(markParam.Gain);
|
|
|
|
}
|
|
|
|
//CamDevFront.SetExposure(markParam.ExposureTime);
|
|
|
|
//CamDevFront.SetGain(markParam.Gain);
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"相机参数设置完成。");
|
|
|
|
@@ -5805,8 +5825,23 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CamDevBack.SetExposure(markParam.ExposureTime);
|
|
|
|
CamDevBack.SetGain(markParam.Gain);
|
|
|
|
|
|
|
|
//完成聚焦之后使用自动曝光
|
|
|
|
if (markParam.AutoExposure)
|
|
|
|
{
|
|
|
|
if (AutoExposureB())
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
|
|
|
|
return stepIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CamDevBack.SetExposure(markParam.ExposureTime);
|
|
|
|
CamDevBack.SetGain(markParam.Gain);
|
|
|
|
}
|
|
|
|
for (int snapi = 0; snapi < snapCnt; snapi++)
|
|
|
|
{
|
|
|
|
DateTime dt = DateTime.Now;
|
|
|
|
@@ -6154,11 +6189,16 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
Log($"{stepIndex + 1}-{processName}", $"轴组运行完成");
|
|
|
|
Thread.Sleep(testParam.WaitTime);
|
|
|
|
|
|
|
|
camDevFront.SetExposure(testParam.ExposureTime);
|
|
|
|
camDevFront.SetGain(testParam.Gain);
|
|
|
|
|
|
|
|
//自动聚焦?
|
|
|
|
if ((this.CurrPoinntCount == 0) && (IsAutoFocus)&& (i == 0))//第一次拍照才聚焦
|
|
|
|
{
|
|
|
|
//判断是否已经自动曝光
|
|
|
|
if (!HaveAutoExp)
|
|
|
|
{
|
|
|
|
camDevFront.SetExposure(testParam.ExposureTime);
|
|
|
|
camDevFront.SetGain(testParam.Gain);
|
|
|
|
}
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动聚焦...");
|
|
|
|
if (!AutoFocus(FocusStep, DirStep, DirWaitTime, FocusTimeOut))
|
|
|
|
{
|
|
|
|
@@ -6169,6 +6209,12 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
}
|
|
|
|
else if (testParam.AutoFocus)//每次都聚焦
|
|
|
|
{
|
|
|
|
//判断是否已经自动曝光
|
|
|
|
if (!HaveAutoExp)
|
|
|
|
{
|
|
|
|
camDevFront.SetExposure(testParam.ExposureTime);
|
|
|
|
camDevFront.SetGain(testParam.Gain);
|
|
|
|
}
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"拍照前自动聚焦...");
|
|
|
|
if (!AutoFocus(testParam.FocusStep, testParam.DirStep, testParam.WaitDoneTime, testParam.TimeOut))
|
|
|
|
{
|
|
|
|
@@ -6177,6 +6223,26 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
}
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"拍照前自动聚焦完成");
|
|
|
|
}
|
|
|
|
|
|
|
|
//完成聚焦之后使用自动曝光
|
|
|
|
if (testParam.AutoExposure && !HaveAutoExp)
|
|
|
|
{
|
|
|
|
if (AutoExposureF())
|
|
|
|
{
|
|
|
|
HaveAutoExp = true;
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
|
|
|
|
return stepIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!testParam.AutoExposure)
|
|
|
|
{
|
|
|
|
camDevFront.SetExposure(testParam.ExposureTime);
|
|
|
|
camDevFront.SetGain(testParam.Gain);
|
|
|
|
}
|
|
|
|
//拍照
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
|
|
|
|
|
|
|
|
@@ -6452,8 +6518,23 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
//拍照
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
|
|
|
|
|
|
|
|
CamDevBack.SetExposure(defectParam.ExposureTime);
|
|
|
|
CamDevBack.SetGain(defectParam.Gain);
|
|
|
|
|
|
|
|
//完成聚焦之后使用自动曝光
|
|
|
|
if (defectParam.AutoExposure)
|
|
|
|
{
|
|
|
|
if (AutoExposureB())
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
|
|
|
|
return stepIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CamDevBack.SetExposure(defectParam.ExposureTime);
|
|
|
|
CamDevBack.SetGain(defectParam.Gain);
|
|
|
|
}
|
|
|
|
|
|
|
|
double px = GetAxisPosValueMM((int)AxisName.Axis1);
|
|
|
|
double py = GetAxisPosValueMM((int)AxisName.Axis2);
|
|
|
|
@@ -10908,6 +10989,151 @@ namespace MaiMuAOI.SysCtrl |
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 自动曝光
|
|
|
|
/// <summary>
|
|
|
|
/// 自动曝光功能前相机
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="exp"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private bool AutoExposureF()
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
Yolo_Class yolo = new Yolo_Class();
|
|
|
|
int exp = 0;
|
|
|
|
double mean = 0;
|
|
|
|
int cnt = 0;
|
|
|
|
DateTime alldt = DateTime.Now;
|
|
|
|
bool breakW = false;
|
|
|
|
|
|
|
|
//获取当前曝光
|
|
|
|
double exp2;
|
|
|
|
camDevFront.GetExposure(out exp2);
|
|
|
|
exp = (int)exp2;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < snapCnt; i++)
|
|
|
|
{
|
|
|
|
camDevFront.ClearImageQueue();
|
|
|
|
Acquisition acq = camDevFront.Snap(1, 5000);
|
|
|
|
if (acq.GrabStatus == "GrabPass")
|
|
|
|
{
|
|
|
|
//显示
|
|
|
|
OnAutoRuning(new RunEventArgs(0, acq.Image));
|
|
|
|
yolo.Exposure(acq.Image.CopyObj(1, -1), ref exp, ref mean);
|
|
|
|
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
Log("自动曝光", $"步进次数:{cnt},曝光:{exp}, Mean:{mean}");
|
|
|
|
if (mean == 9999)
|
|
|
|
{
|
|
|
|
breakW = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!camDevFront.SetExposure(exp))
|
|
|
|
{
|
|
|
|
Log("自动曝光", $"曝光设置失败!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"自动曝光{i}", $"拍照失败{acq.GrabStatus}!");
|
|
|
|
if (i < snapCnt - 1)
|
|
|
|
{
|
|
|
|
Thread.Sleep(100);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (breakW)
|
|
|
|
break;
|
|
|
|
if ((DateTime.Now - alldt).TotalMilliseconds > 10000)
|
|
|
|
{
|
|
|
|
Log("自动曝光", $"自动曝光超时-10ms!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 自动曝光功能后相机
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="exp"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private bool AutoExposureB()
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
Yolo_Class yolo = new Yolo_Class();
|
|
|
|
int exp = 0;
|
|
|
|
double mean = 0;
|
|
|
|
int cnt = 0;
|
|
|
|
DateTime alldt = DateTime.Now;
|
|
|
|
bool breakW = false;
|
|
|
|
|
|
|
|
//获取当前曝光
|
|
|
|
double exp2;
|
|
|
|
camDevBack.GetExposure(out exp2);
|
|
|
|
exp = (int)exp2;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < snapCnt; i++)
|
|
|
|
{
|
|
|
|
camDevBack.ClearImageQueue();
|
|
|
|
Acquisition acq = camDevBack.Snap(1, 5000);
|
|
|
|
if (acq.GrabStatus == "GrabPass")
|
|
|
|
{
|
|
|
|
//显示
|
|
|
|
OnAutoRuning(new RunEventArgs(1, acq.Image));
|
|
|
|
yolo.Exposure(acq.Image.CopyObj(1, -1), ref exp, ref mean);
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
Log("自动曝光", $"步进次数:{cnt},曝光:{exp}, Mean:{mean}");
|
|
|
|
if (mean == 9999)
|
|
|
|
{
|
|
|
|
breakW = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!camDevBack.SetExposure(exp))
|
|
|
|
{
|
|
|
|
Log("自动曝光", $"曝光设置失败!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log($"自动曝光{i}", $"拍照失败{acq.GrabStatus}!");
|
|
|
|
if (i < snapCnt - 1)
|
|
|
|
{
|
|
|
|
Thread.Sleep(100);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (breakW)
|
|
|
|
break;
|
|
|
|
if ((DateTime.Now - alldt).TotalMilliseconds > 10000)
|
|
|
|
{
|
|
|
|
Log("自动曝光", $"自动曝光超时-10s!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 系统事件
|
|
|
|
|