Commit 5d31fcf9 张东亮

添加AOI检测料盘功能

1 个父辈 458e9dcd
......@@ -116,6 +116,8 @@ namespace OnlineStore.Common
#region 视觉检查NG平台
[MyConfigComment("是否使用一维码检测料盘在NG平台")]
public static MyConfig<bool> CamTestReel_useBarcode = false;
[MyConfigComment("是否使用AOI检测料盘在NG平台")]
public static MyConfig<bool> CamTestReel_useAOI = false;
[MyConfigComment("NG平台一维码检测料盘:一维码的内容")]
public static MyConfig<string> CamTestReel_barcode = "RW0000015";
......
此文件类型无法预览
此文件类型无法预览
{"methodMap":"{\"L01\":\"{\\\"SamePercent\\\":80.0,\\\"MethodName\\\":\\\"L01\\\",\\\"FullTypeName\\\":\\\"AOI.AoiTemplateMethod\\\",\\\"PathDataStr\\\":\\\"{\\\\\\\"Points\\\\\\\":[{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":317.0,\\\\\\\"Y\\\\\\\":483.666626},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":553.6666,\\\\\\\"Y\\\\\\\":483.666626},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":553.6666,\\\\\\\"Y\\\\\\\":593.666565},{\\\\\\\"IsEmpty\\\\\\\":false,\\\\\\\"X\\\\\\\":317.0,\\\\\\\"Y\\\\\\\":593.666565}],\\\\\\\"Types\\\\\\\":\\\\\\\"AAEBgQ==\\\\\\\"}\\\"}\"}"}
\ No newline at end of file
......@@ -35,6 +35,9 @@
<Reference Include="AGVLib">
<HintPath>..\DLL\AGVLib.dll</HintPath>
</Reference>
<Reference Include="AOI">
<HintPath>..\DLL\AOI.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary, Version=1.0.8384.25672, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\CodeLibrary.dll</HintPath>
......@@ -159,6 +162,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Config\AOI.data">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Config\Config.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......@@ -176,6 +182,10 @@
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Config\AOI.bmp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -17,6 +17,7 @@ using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
using HalconDotNet;
using System.Web;
using AOI;
namespace DeviceLibrary
{
......@@ -267,6 +268,7 @@ namespace DeviceLibrary
DateTime startTime = DateTime.Now;
Bitmap bmp = null;
bool usebarcode = Setting_Init.CamTestReel_useBarcode;
var useAOI = Setting_Init.CamTestReel_useAOI;
if (usebarcode)
{
try
......@@ -353,6 +355,100 @@ namespace DeviceLibrary
LogUtil.info(logtxt);
}
}
else if (useAOI)
{
try
{
bmp = Camera._cam.GrabOneImage(cameraName, PixelType.RGB8);
if (bmp == null)
{
if (retrytime > 2)
return null;
retrytime++;
Camera._cam.Close(cameraName);
//LoadCamera(true);
LogUtil.info($"{cameraName} bitmap为空重试第{retrytime}次");
Thread.Sleep(2000);
goto retry;
}
logtxt += $"【" + cameraName + "】获取到图像" + "\r\n";
bool hasReel = false;
var projectName = "AOI";
if (Setting_Init.CamTestReel_debug)
srcimg = SaveImageToFile("aoiSrc", cameraName, bmp);
AoiProject project = GetAOIProject(projectName);
if (project != null)
{
if (bmp != null)
{
List<ResultBean> resultBean = project.CheckAll(bmp, out Image outImage);
bool checkResult = true;
string ngList = " AOICheck: " + cameraName + $"," + projectName + ",结果: ";
foreach (ResultBean bean in resultBean)
{
ngList += GetShowName(bean) + "\r\n";
if (bean.result.Equals(false))
{
checkResult = false;
}
}
logtxt += ngList;
hasReel = !checkResult;
if (Setting_Init.CamTestReel_debug || (TestHasRight.HasValue && TestHasRight.Value != hasReel))
{
try
{
using (Bitmap b = new Bitmap(outImage))
prcimg = SaveImageToFile("aoiResult", cameraName, b);
}
catch (Exception ex)
{
LogUtil.LOGGER.Error("AOICheck: 保存结果图失败");
}
}
}
else
{
hasReel = true;
LogUtil.LOGGER.Error("AOICheck: " + cameraName + "." + projectName + $",图片为空");
}
}
else
{
LogUtil.LOGGER.Error("AOICheck: " + cameraName + "." + projectName + ", 获取AOIProject失败");
}
if (hasReel != lastHasReel)
{
lastHasReel = hasReel;
}
else if (!Setting_Init.CamTestReel_debug)
logtxt = "";
TestHasRight = null;
return hasReel;
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
return null;
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
return null;
}
finally
{
if (bmp != null)
bmp.Dispose();
if (!string.IsNullOrEmpty(logtxt))
LogUtil.info(logtxt);
}
}
else
{
try
......@@ -511,6 +607,52 @@ namespace DeviceLibrary
else
return null;
}
private static string GetShowName(ResultBean bean)
{
return (bean.result ? "✔ " : "✘ ") + bean.MethodName + $"({bean.percentValue}%)";
}
#region AOI
private static Dictionary<string, AoiProject> aoiProjectMap = new Dictionary<string, AoiProject>();
private static AoiProject GetAOIProject(string projectName)
{
try
{
string key = $"{projectName}";
if (!aoiProjectMap.ContainsKey(key))
{
string path = Application.StartupPath + $"\\Config\\{projectName}";
AoiProject aoiProject = AoiProject.Load(path, out string msg);
if (aoiProject == null || msg != "")
{
LogUtil.LOGGER.Error("加载 AoiProject " + path + " 失败:" + msg);
return null;
}
else
{
LogUtil.LOGGER.Info("加载 AoiProject " + path);
aoiProjectMap.Add(key, aoiProject);
}
}
return aoiProjectMap[key];
}
catch (Exception e)
{
LogUtil.LOGGER.Error("GetAOIProject 出错: " + e.ToString());
}
return null;
}
#endregion
/// <summary>
///
/// </summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!