diff --git a/halftoneproject-master/BanBoShi/BanBoShi.csproj b/halftoneproject-master/BanBoShi/BanBoShi.csproj
index 21a79337..70644870 100644
--- a/halftoneproject-master/BanBoShi/BanBoShi.csproj
+++ b/halftoneproject-master/BanBoShi/BanBoShi.csproj
@@ -208,7 +208,7 @@
False
- ..\..\Dlls\Yolo5.dll
+ Dlls\Yolo5.dll
..\packages\ZstdSharp.Port.0.7.1\lib\net461\ZstdSharp.dll
diff --git a/halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs b/halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs
index fcb0aa73..dac1d701 100644
--- a/halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs
+++ b/halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs
@@ -98,6 +98,10 @@ namespace MaiMuAOI.SysCtrl
///
private int CurrPoinntCount = 0;
///
+ /// 尺寸检测是否自动曝光完成
+ ///
+ private bool HaveAutoExp = false;
+ ///
/// 总计时
///
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 自动曝光
+ ///
+ /// 自动曝光功能前相机
+ ///
+ ///
+ ///
+ 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;
+ }
+
+ ///
+ /// 自动曝光功能后相机
+ ///
+ ///
+ ///
+ 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 系统事件
diff --git a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs
index 93e5fd8a..ffbe2aa7 100644
--- a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs
+++ b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs
@@ -27,9 +27,11 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(14), Browsable(true), Category("2 Mark"), DisplayName("2.4 手动Mark位置列表"), Description("当自动寻找Mark False时,需要手动输入Mark点位")]
public List Points { get; set; }
- [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
+ [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
+ public bool AutoExposure { get; set; }
+ [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
- [PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.2 增益"), Description("增益")]
+ [PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("4 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -54,6 +56,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
AutoMark = true;
Points = new List();
+ AutoExposure = false;
ExposureTime = 30000;
Gain = 0;
diff --git a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs
index 5c17af89..ecccd46b 100644
--- a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs
+++ b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs
@@ -35,9 +35,12 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(17), Browsable(true), Category("2 检测"), DisplayName("2.6 数据判定方式"), Description("对采集数据进行判定处理的方式")]
public DataJudgment JudgmentData { get; set; }
- [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
+
+ [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
+ public bool AutoExposure { get; set; }
+ [PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
- [PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.2 增益"), Description("增益")]
+ [PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("4 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -115,6 +118,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
Points = new List();
JudgmentData = DataJudgment.均值;
+ AutoExposure = false;
ExposureTime = 30000;
Gain = 0;
diff --git a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs
index 269a19f7..0aa5c288 100644
--- a/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs
+++ b/halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs
@@ -31,9 +31,11 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(17), Browsable(true), Category("02 缺陷检测"), DisplayName("2.7 异步运行"), Description("非阻塞后续流程运行(True-是;False-否)")]
public bool AsynDefectRun { get; set; } = true;
- [PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
+ [PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
+ public bool AutoExposure { get; set; }
+ [PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
- [PropertyOrder(22), Browsable(true), Category("03 相机"), DisplayName("3.2 增益"), Description("增益")]
+ [PropertyOrder(22), Browsable(true), Category("03 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("04 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -117,6 +119,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
Thresholds = ConfMgr.Instance.SysConfigParams.Defect_Thresholds;
AsynDefectRun = true;
+ AutoExposure = false;
ExposureTime = 30000;
Gain = 0;