Commit 4de1a697 张东亮

AOI检测测试ok

1 个父辈 5d31fcf9
...@@ -118,6 +118,8 @@ namespace OnlineStore.Common ...@@ -118,6 +118,8 @@ namespace OnlineStore.Common
public static MyConfig<bool> CamTestReel_useBarcode = false; public static MyConfig<bool> CamTestReel_useBarcode = false;
[MyConfigComment("是否使用AOI检测料盘在NG平台")] [MyConfigComment("是否使用AOI检测料盘在NG平台")]
public static MyConfig<bool> CamTestReel_useAOI = false; public static MyConfig<bool> CamTestReel_useAOI = false;
[MyConfigComment("NG平台AOI检测料盘:总的面积。大于认为有料")]
public static MyConfig<int> CamTestReel_AOITotalArea = 300;
[MyConfigComment("NG平台一维码检测料盘:一维码的内容")] [MyConfigComment("NG平台一维码检测料盘:一维码的内容")]
public static MyConfig<string> CamTestReel_barcode = "RW0000015"; public static MyConfig<string> CamTestReel_barcode = "RW0000015";
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.11.0.20250507\build\netstandard\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.11.0.20250507\build\netstandard\OpenCvSharp4.runtime.win.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
...@@ -13,6 +14,8 @@ ...@@ -13,6 +14,8 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
...@@ -35,8 +38,8 @@ ...@@ -35,8 +38,8 @@
<Reference Include="AGVLib"> <Reference Include="AGVLib">
<HintPath>..\DLL\AGVLib.dll</HintPath> <HintPath>..\DLL\AGVLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="AOI"> <Reference Include="Asa.Camera.VisionLib">
<HintPath>..\DLL\AOI.dll</HintPath> <HintPath>..\DLL\Asa.Camera.VisionLib.dll</HintPath>
</Reference> </Reference>
<Reference Include="CodeLibrary, Version=1.0.8384.25672, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="CodeLibrary, Version=1.0.8384.25672, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
...@@ -59,10 +62,32 @@ ...@@ -59,10 +62,32 @@
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp4.4.11.0.20250507\lib\netstandard2.0\OpenCvSharp.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp4.Extensions.4.11.0.20250507\lib\netstandard2.0\OpenCvSharp.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Common.8.0.11\lib\net462\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
...@@ -79,6 +104,7 @@ ...@@ -79,6 +104,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" /> <Compile Include="DeviceLibrary\AcSerialBean.cs" />
<Compile Include="DeviceLibrary\Camera.cs" /> <Compile Include="DeviceLibrary\Camera.cs" />
<Compile Include="DeviceLibrary\CameraReelCheck.cs" />
<Compile Include="DeviceLibrary\CameraTest.cs" /> <Compile Include="DeviceLibrary\CameraTest.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" /> <Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\dauxiKS107\DauxiKS107Controller.cs" /> <Compile Include="DeviceLibrary\dauxiKS107\DauxiKS107Controller.cs" />
...@@ -162,6 +188,7 @@ ...@@ -162,6 +188,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" />
<None Include="Config\AOI.data"> <None Include="Config\AOI.data">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
...@@ -188,4 +215,10 @@ ...@@ -188,4 +215,10 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.11.0.20250507\build\netstandard\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.11.0.20250507\build\netstandard\OpenCvSharp4.runtime.win.props'))" />
</Target>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
using CodeLibrary; using DeviceLibrary;
using DeviceLibrary;
using OnlineStore; using OnlineStore;
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
public class HIKCamera public class HIKCamera
{ {
...@@ -20,53 +13,52 @@ public class HIKCamera ...@@ -20,53 +13,52 @@ public class HIKCamera
public event EventHandler<Bitmap> camera_event; public event EventHandler<Bitmap> camera_event;
public string DeviceName = "monitor1"; public string DeviceName = "monitor1";
public PictureBox picture = new PictureBox(); public PictureBox picture = new PictureBox();
//public bool LoadCameraConfig(out string msg, object preview = null) //Asa.Camera.VisionLib camera;
//public bool LoadCameraConfig(string CameraID, out string msg)
//{ //{
// Name = CameraID;
// msg = ""; // msg = "";
// if (!enableCamera) return true; // //string path = $"D\\X800\\Config\\{CameraID}.json";
// string path = $".\\Config\\IPCamera.json"; // string path = CommonLib.GetPath(@"Config\CameraA.json");
// if (!File.Exists(path)) // if (!File.Exists(path))
// { // {
// msg = crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件"); // msg = Name + crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
// LogUtil.error("找不到监控相机配置文件" + path); // LogUtil.error(Name + "找不到监控相机配置文件" + path);
// return false; // return false;
// } // }
// try // try
// { // {
// if (!VideoManager.LoadCamera(path, out string loadmsg))
// var configtxt = File.ReadAllText(path);
// if (configtxt.IndexOf("Pwd") > 0)
// { // {
// msg = loadmsg; // configtxt = configtxt.Replace("Pwd", "Password");
// configtxt = configtxt.Replace("\"8000\"", "8000");
// File.WriteAllText(path, configtxt);
// } // }
// var m = Regex.Match(configtxt, "name\".*?\"(.+)\"", RegexOptions.IgnoreCase);
// DeviceName = m.Groups[1].Value;
// camera = new Asa.Camera.VisionLib(path, true, "HIKIPCamera");
// } // }
// catch (Exception e) // catch (Exception e)
// { // {
// msg = crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString(); // msg = Name + crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
// LogUtil.error("加载监控相机配置文件失败:" + e.ToString()); // LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
// return false; // return false;
// } // }
// if (VideoManager.CamNames != null && VideoManager.CamNames.Count > 0) // camera.Open(DeviceName);
// { // //Bitmap bmp = camera.GetImage(DeviceName);
// Name = VideoManager.CamNames[0]; // //if (bmp == null)
// if (preview == null) // //{
// { // // msg = Name + crc.GetString(L.monitor_open_fail,"监控相机打开失败");
// VideoManager.Open(new Dictionary<string, IntPtr> { { Name, picture.Handle } }); // // LogUtil.error(Name + $"监控相机打开失败");
// } // // return false;
// else // //}
// { // //camerathread = new Thread(new ThreadStart(startCamera));
// VideoManager.Open(new Dictionary<string, IntPtr> { { Name, (IntPtr)preview } }); // //camerathread.Start();
// } // //GC.KeepAlive(camerathread);
// VideoManager.GrabOneImg(Name, out Bitmap bmp);
// if (bmp == null) // return true;
// {
// msg = Name + crc.GetString(L.monitor_open_fail, "监控相机打开失败");
// LogUtil.error(Name + $"监控相机打开失败");
// return false;
// }
// VideoManager.StartRecord(Name, "Auto1");
// camera_event?.Invoke(this, bmp);
// return true;
// }
// return false;
//} //}
int errortimes = 0; int errortimes = 0;
bool camerathreadrun = true; bool camerathreadrun = true;
...@@ -103,6 +95,15 @@ public class HIKCamera ...@@ -103,6 +95,15 @@ public class HIKCamera
// LogUtil.error(Name + e.ToString()); // LogUtil.error(Name + e.ToString());
//} //}
} }
public Bitmap GetImage(int index)
{
return null;
//if (camera == null)
// return null;
//return camera.GetImage(index);
}
public string GetFixtureStateFilename(string PositionNum, string WareNumber, StoreMoveType storeMoveType, FixtureState fixtureState) public string GetFixtureStateFilename(string PositionNum, string WareNumber, StoreMoveType storeMoveType, FixtureState fixtureState)
{ {
Path.GetInvalidFileNameChars().ToList().ForEach((ix) => { WareNumber = WareNumber.Replace(ix.ToString(), ""); }); Path.GetInvalidFileNameChars().ToList().ForEach((ix) => { WareNumber = WareNumber.Replace(ix.ToString(), ""); });
......
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class CameraReelCheck
{
public static List<CameraReelCheck> List = new List<CameraReelCheck>();
static DateTime lastChecktime2 = DateTime.MinValue;
public static bool WaitCheckAll(params CameraReelCheck[] reelCheck)
{
if (reelCheck.All(r => !r.NeedWaitEx()))
{
//if ((DateTime.Now - lastChecktime2).TotalSeconds > 3)
//{
// reelCheck.AsParallel().ForAll(r => r.Reset());
// return true;
//}
lastChecktime2 = DateTime.Now;
reelCheck.AsParallel().ForAll(r => r.Reset());
return false;
}
return true;
}
int IPCameraID = 0;
string MVSCameraID = string.Empty;
//string CameraID;
public string Name;
Mat template_mat = new Mat();
Mat template_mask = new Mat();
double maskcount = 0;
BackgroundSubtractorMOG2 bgs = null;
/// <summary>
/// 初始化ipcamera
/// </summary>
/// <param name="name">名称,不重复</param>
/// <param name="cameraID"></param>
/// <param name="_scale">根据图像尺寸调节缩放比例, 缩小后分辨率在600~1500左右</param>
public CameraReelCheck(string name, int cameraID, int _scale = 3)
{
scale = _scale;
IPCameraID = cameraID;
Name = name;
List.Add(this);
loadtemplate();
}
/// <summary>
/// 初始化mvs
/// </summary>
/// <param name="name"></param>
/// <param name="camenraID"></param>
/// <param name="_scale">根据图像尺寸调节缩放比例, 缩小后分辨率在600~1500左右</param>
public CameraReelCheck(string name, string camenraID, int _scale = 3)
{
scale = _scale;
MVSCameraID = camenraID;
Name = name;
List.Add(this);
loadtemplate();
}
int scale = 3;
/// <summary>
/// 加载模版
/// </summary>
public void loadtemplate()
{
if (File.Exists(templateMaskfile))
{
var t = Cv2.ImRead(templateMaskfile, ImreadModes.Grayscale);
t = t.Resize(new OpenCvSharp.Size(t.Width / scale, t.Height / scale));
Cv2.Threshold(t, template_mask, 254, 255, ThresholdTypes.Binary);
t.Dispose();
OpenCvSharp.Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(template_mask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
template_mask.SetTo(0);
foreach (var contour in contours)
{
var tc = Cv2.ContourArea(contour);
if (tc > 4000)
{
Cv2.FillPoly(template_mask, new OpenCvSharp.Point[][] { contour }, Scalar.White);
LogUtil.info(Name + " 加载到模版范围计数:" + tc);
maskcount = tc;
}
}
//template_mask.SaveImage(@"d:\logs\mask.bmp");
}
reflashtemplate(true);
}
void reflashtemplate(bool islog = false)
{
lock (this)
{
var tpcount = templatefiles.Length;
bgs?.Dispose();
bgs = BackgroundSubtractorMOG2.Create(tpcount, 90, false);
var fg = new Mat();
foreach (var templatefile in templatefiles.ToArray())
{
if (File.Exists(templatefile))
{
try
{
template_mat = Cv2.ImRead(templatefile, ImreadModes.Color);
template_mat = template_mat.Resize(new OpenCvSharp.Size(template_mat.Width / scale, template_mat.Height / scale));
bgs.Apply(template_mat, fg);
if (islog)
LogUtil.info("加载到模版文件:" + templatefile);
}
catch (Exception ex)
{
LogUtil.error("图像文件加载失败:" + templatefile);
}
}
}
fg.Dispose();
}
}
Task<bool?> cameraTestTask;
DateTime lastChecktime = DateTime.MinValue;
/// <summary>
/// 是否需要等待检测
/// </summary>
public bool NeedWait()
{
if ((DateTime.Now - lastChecktime).TotalSeconds <= 2)
{
return false;
}
if (cameraTestTask == null)
{
StartACheck(null);
return true;
}
if (cameraTestTask.IsCompleted)
{
if ((DateTime.Now - lastChecktime).TotalSeconds > 2)
{
StartACheck(null);
return true;
}
if (!cameraTestTask.Result.HasValue)
{
StartACheck(null);
return true;
}
else
{
StartACheck(null);
return false;
}
}
return true;
}
internal bool NeedWaitEx()
{
if ((DateTime.Now - lastChecktime).TotalSeconds <= 2)
{
return false;
}
if (cameraTestTask == null)
{
StartACheck(null);
return true;
}
if (cameraTestTask.IsCompleted)
{
if (!cameraTestTask.Result.HasValue)
{
StartACheck(null);
return true;
}
else
{
return false;
}
}
return true;
}
volatile bool hasReel = false;
double totalArea = 0;
/// <summary>
/// 是否有料盘, 检测前调用 ResetAndCheck
/// </summary>
public bool HasReel { get => hasReel; }
public double TotalArea { get => totalArea; }
/// <summary>
/// 重置检测结果
/// </summary>
public void Reset()
{
cameraTestTask = null;
}
/// <summary>
/// 重置检测结果,并立刻开始检测
/// </summary>
public void ResetAndCheck(MoveInfo moveInfo, bool saveimage = false)
{
cameraTestTask = null;
StartACheck(moveInfo, saveimage);
}
string templatepath = CommonLib.GetPath("CameraTemplate");
string templateBGpath
{
get
{
var d = CommonLib.GetPath($"CameraTemplate\\Template\\T{Name}");
Directory.CreateDirectory(d);
return d;
}
}
//{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}_
string[] templatefiles { get => Directory.GetFiles(templateBGpath, "*Empty.bmp", SearchOption.TopDirectoryOnly); }
string templateMaskfile { get => Path.Combine(templateBGpath, $"Mask.bmp"); }
/// <summary>
/// 保存背景模版
/// </summary>
public bool SaveBackgroundTemplate()
{
Bitmap bmp = null;
try
{
bmp = GetImage();
Directory.CreateDirectory(templateBGpath);
if (bmp == null)
return false;
else
{
bmp?.Save(Path.Combine(templateBGpath, $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}_Empty.bmp"));
var files = Directory.GetFiles(templateBGpath)
.Select(f => new FileInfo(f))
.Where(fi => !fi.Name.ToLower().Contains("mask")) // 只保留包含"mask"的文件
.OrderBy(fi => fi.LastWriteTime); // 按最后写入时间排序
var tl = files.Count() - 6;
if (tl > 0)
{
var fs = files.Take(tl).ToList();
fs.ForEach(f => f.Delete());
}
}
//template_mat?.Dispose();
return true;
}
finally
{
bmp?.Dispose();
loadtemplate();
}
}
/// <summary>
/// 获取图像的方法
/// </summary>
/// <returns></returns>
Bitmap GetImage()
{
if (MVSCameraID == string.Empty)
{
return RobotManage.CameraA.GetImage(IPCameraID);
}
else
{
return Camera._cam.GrabOneImage(MVSCameraID, PixelType.RGB8); ;
//List<CodeInfo> codeinfos = new List<CodeInfo>();
//if (MVSCameraID.Count(c => c == '.') == 3)
// bmp = IDHIK.Lamberv.GrabOne(MVSCameraID, null, out codeinfos);
//else
// bmp = IDHIK.Instance.GrabOne(MVSCameraID, null, out codeinfos);
//if (codeinfos.Count > 0)
// return new Bitmap(1, 1);
//else
// return (Bitmap)bmp;
}
}
Mat foround = null;
[HandleProcessCorruptedStateExceptions]
public void StartACheck(MoveInfo moveInfo, bool saveimage = false)
{
if (saveimage)
LogUtil.info(Name + "启动检测:" + templateBGpath);
cameraTestTask = System.Threading.Tasks.Task.Run(new Func<bool?>(() =>
{
try
{
foround?.Dispose();
if (saveimage)
LogUtil.info(Name + "开始检测:" + templateBGpath);
var t = ", ";
Stopwatch stopwatch = Stopwatch.StartNew();
reflashtemplate();
t += stopwatch.ElapsedMilliseconds + ", ";
var bmp = GetImage();
//var bmp = new Bitmap(@"D:\2024-12-03-16-34-26_Empty.bmp");
if (bmp == null)
{
if (saveimage)
LogUtil.info(Name + "没有获取到图像");
return null;
}
try
{
if (bmp.Size.Width == 1)
{
lastChecktime = DateTime.Now;
//if (saveimage)
LogUtil.info(Name + "读取到条码,直接算有盘");
hasReel = true;
return true;
}
t += stopwatch.ElapsedMilliseconds + ", ";
foround = bmp.ToMat();
foround = foround.Resize(new OpenCvSharp.Size(foround.Width / scale, foround.Height / scale));
if (saveimage)
{
LogUtil.info(Name + " 保存原始图像:" + Path.Combine(templatepath, $"{Name}_org.bmp"));
bmp.Save(Path.Combine(templatepath, $"{Name}_org.bmp"));
}
}
catch (Exception e)
{
LogUtil.error(Name + "保存原始图像出错:" + e.ToString());
return false;
}
finally
{
bmp?.Dispose();
}
Mat foroundMasked = new Mat();
Mat thresh = new Mat();
bgs.Apply(foround, foroundMasked);
//foroundMasked.SaveImage(@"d:\logs\fs1.bmp");
foroundMasked.CopyTo(thresh, template_mask);
//thresh.SaveImage(@"d:\logs\fs2.bmp");
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Ellipse, new OpenCvSharp.Size(3, 3));
Cv2.MorphologyEx(thresh, thresh, MorphTypes.Open, kernel);
// 检测轮廓
OpenCvSharp.Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(thresh, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
totalArea = 0;
double noneMax = 0;
// 在原始图像上绘制轮廓
foreach (var contour in contours)
{
var c = Cv2.ContourArea(contour);
if (c > 300)
{
totalArea += c;
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.Red, 2);
}
else
{
if (c > noneMax)
noneMax = c;
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.DarkGreen, 2);
}
}
t += "E:" + stopwatch.ElapsedMilliseconds + ", N:" + noneMax;
Cv2.PutText(foround, totalArea.ToString() + t, new OpenCvSharp.Point(50 / scale, 100 / scale), HersheyFonts.HersheyPlain, 2 / scale, Scalar.Red, 2 / scale);
Cv2.FindContours(template_mask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
// 在原始图像上绘制轮廓
foreach (var contour in contours)
{
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.Yellow, 1);
}
//File.Delete(Path.Combine(templatepath, $"{CameraID}_result.bmp"));
foround.SaveImage(Path.Combine(templatepath, $"{Name}_result.bmp"));
if (MVSCameraID == string.Empty && totalArea > maskcount * 0.95)
{
LogUtil.info(Name + $"疑似画面异常:totalArea:{totalArea}");
foround.SaveImage(Path.Combine(templatepath, $"{Name}_break.bmp"));
return false;
}
else
{
hasReel = totalArea > 300;
}
foroundMasked.Dispose();
thresh.Dispose();
kernel.Dispose();
lastChecktime = DateTime.Now;
return true;
}
catch (Exception ex)
{
LogUtil.error(Name + $"Camera error ID:{Name} " + ex);
}
return true;
}));
moveInfo?.WaitList.Add(WaitResultInfo.WaitAction((w) => { return cameraTestTask.IsCompleted; }, crc.GetString("Res0017.343f7565", "等待检测料盘是否存在")));
}
[HandleProcessCorruptedStateExceptions]
public bool ReelCheck(Bitmap bitmap, bool saveimage = false)
{
hasReel = true;
if (saveimage)
LogUtil.info(Name + "启动检测:" + templateBGpath);
try
{
foround?.Dispose();
if (saveimage)
LogUtil.info(Name + "开始检测:" + templateBGpath);
var t = ", ";
Stopwatch stopwatch = Stopwatch.StartNew();
reflashtemplate();
t += stopwatch.ElapsedMilliseconds + ", ";
var bmp = bitmap;
//var bmp = new Bitmap(@"D:\2024-12-03-16-34-26_Empty.bmp");
if (bmp == null)
{
if (saveimage)
LogUtil.info(Name + "没有获取到图像");
return true;
}
try
{
if (bmp.Size.Width == 1)
{
lastChecktime = DateTime.Now;
//if (saveimage)
LogUtil.info(Name + "读取到条码,直接算有盘");
hasReel = true;
return true;
}
t += stopwatch.ElapsedMilliseconds + ", ";
foround = bmp.ToMat();
foround = foround.Resize(new OpenCvSharp.Size(foround.Width / scale, foround.Height / scale));
if (saveimage)
{
LogUtil.info(Name + " 保存原始图像:" + Path.Combine(templatepath, $"{Name}_org.bmp"));
bmp.Save(Path.Combine(templatepath, $"{Name}_org.bmp"));
}
}
catch (Exception e)
{
LogUtil.error(Name + "保存原始图像出错:" + e.ToString());
return false;
}
finally
{
bmp?.Dispose();
}
Mat foroundMasked = new Mat();
Mat thresh = new Mat();
bgs.Apply(foround, foroundMasked);
//foroundMasked.SaveImage(@"d:\logs\fs1.bmp");
foroundMasked.CopyTo(thresh, template_mask);
//thresh.SaveImage(@"d:\logs\fs2.bmp");
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Ellipse, new OpenCvSharp.Size(3, 3));
Cv2.MorphologyEx(thresh, thresh, MorphTypes.Open, kernel);
// 检测轮廓
OpenCvSharp.Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(thresh, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
totalArea = 0;
double noneMax = 0;
// 在原始图像上绘制轮廓
foreach (var contour in contours)
{
var c = Cv2.ContourArea(contour);
if (c > 300)
{
totalArea += c;
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.Red, 2);
}
else
{
if (c > noneMax)
noneMax = c;
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.DarkGreen, 2);
}
}
t += "E:" + stopwatch.ElapsedMilliseconds + ", N:" + noneMax;
Cv2.PutText(foround, totalArea.ToString() + t, new OpenCvSharp.Point(50 / scale, 100 / scale), HersheyFonts.HersheyPlain, 2 / scale, Scalar.Red, 2 / scale);
Cv2.FindContours(template_mask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
// 在原始图像上绘制轮廓
foreach (var contour in contours)
{
Cv2.DrawContours(foround, new OpenCvSharp.Point[][] { contour }, -1, Scalar.Yellow, 1);
}
//File.Delete(Path.Combine(templatepath, $"{CameraID}_result.bmp"));
if (saveimage)
foround.SaveImage(Path.Combine(templatepath, $"{Name}_result.bmp"));
var maxTotal = Setting_Init.CamTestReel_AOITotalArea;
if (MVSCameraID == string.Empty && totalArea > maskcount * 0.95)
{
LogUtil.info(Name + $"疑似画面异常:totalArea:{totalArea}");
foround.SaveImage(Path.Combine(templatepath, $"{Name}_break.bmp"));
return false;
}
else
{
hasReel = totalArea > maxTotal;
}
if(saveimage)
{
LogUtil.info(Name + $"totalArea:{totalArea},阈值:{maxTotal},结果:{(hasReel ? "有料" : "无料")}");
}
foroundMasked.Dispose();
thresh.Dispose();
kernel.Dispose();
lastChecktime = DateTime.Now;
return hasReel;
}
catch (Exception ex)
{
LogUtil.error(Name + $"Camera error ID:{Name} " + ex);
}
return true;
}
public static System.Drawing.Point FindReelCenter(Bitmap bitmap)
{
var t = Cv2.ImRead(CommonLib.GetPath("CameraTemplate\\Template\\LabelMask.bmp"), ImreadModes.Grayscale);
Mat template_mask = new Mat();
Cv2.Threshold(t, template_mask, 254, 255, ThresholdTypes.Binary);
t.Dispose();
var src = bitmap.ToMat();
// 2. 转为灰度图
Mat gray = new Mat();
Cv2.CvtColor(src, gray, ColorConversionCodes.BGR2GRAY);
Mat binary = new Mat();
Cv2.Threshold(gray, binary, 25, 255, ThresholdTypes.Binary);
Cv2.BitwiseAnd(binary, template_mask, binary);
// 创建一个内核(用于腐蚀/膨胀)
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(7, 7));
// 腐蚀操作(移除细线)
Mat eroded = new Mat();
Cv2.Erode(binary, binary, kernel);
Moments moments = Cv2.Moments(binary, true);
if (moments.M00 != 0)
{
int cx = (int)(moments.M10 / moments.M00);
int cy = (int)(moments.M01 / moments.M00);
// 打印质心坐标
//Console.WriteLine($"Combined Centroid: ({cx}, {cy})");
// 在图像中标记质心
Mat result = new Mat();
Cv2.CvtColor(binary, result, ColorConversionCodes.GRAY2BGR);
Cv2.Circle(result, new OpenCvSharp.Point(cx, cy), 15, Scalar.Red, -1);
result.SaveImage(CommonLib.GetPath("CameraTemplate\\LabelMoments.jpg"));
result.Dispose();
binary.Dispose();
//Cv2.ImShow("bbb", result);
//Cv2.WaitKey(13000);
return new System.Drawing.Point(cx, cy);
}
return System.Drawing.Point.Empty;
}
public static void test()
{
//CameraReelCheck cc = new CameraReelCheck("UM1_1_Check", 0, 1);
//cc.ResetAndCheck(null, true);
return;
var t = Cv2.ImRead(@"D:\Image_20241205171329991.jpg", ImreadModes.Grayscale);
Mat template_mask = new Mat();
Cv2.Threshold(t, template_mask, 254, 255, ThresholdTypes.Binary);
t.Dispose();
OpenCvSharp.Point[][] contours1;
HierarchyIndex[] hierarchy;
Cv2.FindContours(template_mask, out contours1, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
template_mask.SetTo(0);
foreach (var contour in contours1)
{
if (Cv2.ContourArea(contour) > 4000)
Cv2.FillPoly(template_mask, new OpenCvSharp.Point[][] { contour }, Scalar.White);
}
Cv2.NamedWindow("bbb", WindowFlags.Normal);
Cv2.ImShow("bbb", template_mask);
Cv2.WaitKey(13000);
//
var src = Cv2.ImRead(@"D:\Image_20241205171329991.jpg");
// 2. 转为灰度图
Mat gray = new Mat();
Cv2.CvtColor(src, gray, ColorConversionCodes.BGR2GRAY);
Mat binary = new Mat();
Cv2.Threshold(gray, binary, 25, 255, ThresholdTypes.Binary);
Cv2.BitwiseAnd(binary, template_mask, binary);
// 创建一个内核(用于腐蚀/膨胀)
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(7, 7));
// 腐蚀操作(移除细线)
Mat eroded = new Mat();
Cv2.Erode(binary, binary, kernel);
//// 膨胀操作(恢复较大区域)
//Mat cleaned = new Mat();
// Cv2.Dilate(eroded, binary, kernel);
// 找到轮廓
//Cv2.FindContours(binary, out OpenCvSharp.Point[][] contours, out _, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
// 创建一张用于显示的图像
//Mat result = new Mat();
//Cv2.CvtColor(binary, result, ColorConversionCodes.GRAY2BGR);
// 计算几何矩
Moments moments = Cv2.Moments(binary, true);
// 计算合并质心
if (moments.M00 != 0)
{
int cx = (int)(moments.M10 / moments.M00);
int cy = (int)(moments.M01 / moments.M00);
// 打印质心坐标
Console.WriteLine($"Combined Centroid: ({cx}, {cy})");
// 在图像中标记质心
Mat result = new Mat();
Cv2.CvtColor(binary, result, ColorConversionCodes.GRAY2BGR);
Cv2.Circle(result, new OpenCvSharp.Point(cx, cy), 15, Scalar.Red, -1);
//bgs.Apply(m2, fg);
Cv2.ImShow("bbb", result);
Cv2.WaitKey(13000);
}
Environment.Exit(0);
}
//internal void saveReelTracedimage(string posname, string rI)
//{
// var p = Path.Combine(Setting_Init.DataStorage_Directory, $"image\\AOI_{posname}");
// Directory.CreateDirectory(p);
// foround.SaveImage(Path.Combine(p, $"{rI}.bmp"));
//}
}
}
\ No newline at end of file \ No newline at end of file
...@@ -17,7 +17,6 @@ using System.Runtime.InteropServices; ...@@ -17,7 +17,6 @@ using System.Runtime.InteropServices;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using HalconDotNet; using HalconDotNet;
using System.Web; using System.Web;
using AOI;
namespace DeviceLibrary namespace DeviceLibrary
{ {
...@@ -102,6 +101,11 @@ namespace DeviceLibrary ...@@ -102,6 +101,11 @@ namespace DeviceLibrary
hikNameList.Add(n); hikNameList.Add(n);
} }
} }
if (hikNameList != null && hikNameList.Count > 0)
{
if (cameraReelCheck == null)
cameraReelCheck = new CameraReelCheck("NGDoor", hikNameList[0]);
}
// hikNameList.AddRange(names); // hikNameList.AddRange(names);
foreach (string name in hikNameList) foreach (string name in hikNameList)
{ {
...@@ -253,6 +257,7 @@ namespace DeviceLibrary ...@@ -253,6 +257,7 @@ namespace DeviceLibrary
static bool lastHasReel = false; static bool lastHasReel = false;
public static bool? TestHasRight = null; public static bool? TestHasRight = null;
static object testLocObj = new object(); static object testLocObj = new object();
static CameraReelCheck cameraReelCheck;
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static bool? TestHasReel(string cameraName, out string srcimg, out string prcimg) public static bool? TestHasReel(string cameraName, out string srcimg, out string prcimg)
{ {
...@@ -373,53 +378,7 @@ namespace DeviceLibrary ...@@ -373,53 +378,7 @@ namespace DeviceLibrary
goto retry; goto retry;
} }
logtxt += $"【" + cameraName + "】获取到图像" + "\r\n"; logtxt += $"【" + cameraName + "】获取到图像" + "\r\n";
bool hasReel = false; bool hasReel = cameraReelCheck.ReelCheck(bmp, Setting_Init.CamTestReel_debug);
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) if (hasReel != lastHasReel)
{ {
...@@ -607,46 +566,139 @@ namespace DeviceLibrary ...@@ -607,46 +566,139 @@ namespace DeviceLibrary
else else
return null; 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; //try
} //{
else // bmp = Camera._cam.GrabOneImage(cameraName, PixelType.RGB8);
{ // if (bmp == null)
LogUtil.LOGGER.Info("加载 AoiProject " + path); // {
aoiProjectMap.Add(key, aoiProject); // if (retrytime > 2)
} // return null;
} // retrytime++;
// Camera._cam.Close(cameraName);
return aoiProjectMap[key]; // //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);
//}
//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>();
catch (Exception e) //private static AoiProject GetAOIProject(string projectName)
{ //{
LogUtil.LOGGER.Error("GetAOIProject 出错: " + e.ToString()); // try
} // {
return null; // 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 #endregion
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" /> <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" />
<package id="OpenCvSharp4" version="4.11.0.20250507" targetFramework="net462" />
<package id="OpenCvSharp4.Extensions" version="4.11.0.20250507" targetFramework="net462" />
<package id="OpenCvSharp4.runtime.win" version="4.11.0.20250507" targetFramework="net462" />
<package id="System.Buffers" version="4.6.1" targetFramework="net462" />
<package id="System.Drawing.Common" version="8.0.11" targetFramework="net462" />
<package id="System.Memory" version="4.6.3" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net462" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages> </packages>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<configSections> <configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
...@@ -66,6 +66,18 @@ ...@@ -66,6 +66,18 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
<system.web> <system.web>
......
...@@ -59,7 +59,7 @@ namespace TheMachine ...@@ -59,7 +59,7 @@ namespace TheMachine
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{ {
LogUtil.error($"Application_ThreadException:" + e.ToString()); LogUtil.error($"Application_ThreadException:" + $"{e.Exception.ToString()}");
} }
......
...@@ -39,6 +39,7 @@ namespace TheMachine ...@@ -39,6 +39,7 @@ namespace TheMachine
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.uC_LedConfig1 = new TheMachine.UC_LedConfig(); this.uC_LedConfig1 = new TheMachine.UC_LedConfig();
this.uC_SetUserPassword1 = new TheMachine.UC_SetUserPassword(); this.uC_SetUserPassword1 = new TheMachine.UC_SetUserPassword();
this.btn_careCameraTemplate = new System.Windows.Forms.Button();
this.tp.SuspendLayout(); this.tp.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -152,10 +153,21 @@ namespace TheMachine ...@@ -152,10 +153,21 @@ namespace TheMachine
this.uC_SetUserPassword1.TabIndex = 8; this.uC_SetUserPassword1.TabIndex = 8;
this.uC_SetUserPassword1.Tag = "not"; this.uC_SetUserPassword1.Tag = "not";
// //
// btn_careCameraTemplate
//
this.btn_careCameraTemplate.Location = new System.Drawing.Point(15, 195);
this.btn_careCameraTemplate.Name = "btn_careCameraTemplate";
this.btn_careCameraTemplate.Size = new System.Drawing.Size(332, 43);
this.btn_careCameraTemplate.TabIndex = 10;
this.btn_careCameraTemplate.Text = "保存料盘检测背景模版";
this.btn_careCameraTemplate.UseVisualStyleBackColor = true;
this.btn_careCameraTemplate.Click += new System.EventHandler(this.btn_careCameraTemplate_Click);
//
// SettingControl // SettingControl
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.AutoScroll = true; this.AutoScroll = true;
this.Controls.Add(this.btn_careCameraTemplate);
this.Controls.Add(this.uC_LedConfig1); this.Controls.Add(this.uC_LedConfig1);
this.Controls.Add(this.uC_SetUserPassword1); this.Controls.Add(this.uC_SetUserPassword1);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
...@@ -180,5 +192,6 @@ namespace TheMachine ...@@ -180,5 +192,6 @@ namespace TheMachine
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private UC_SetUserPassword uC_SetUserPassword1; private UC_SetUserPassword uC_SetUserPassword1;
private UC_LedConfig uC_LedConfig1; private UC_LedConfig uC_LedConfig1;
private System.Windows.Forms.Button btn_careCameraTemplate;
} }
} }
...@@ -130,6 +130,23 @@ namespace TheMachine ...@@ -130,6 +130,23 @@ namespace TheMachine
Task.Run(() => CodeManager.TestHasReel(CodeManager.hikNameList[0], out _, out _)); Task.Run(() => CodeManager.TestHasReel(CodeManager.hikNameList[0], out _, out _));
} }
private void btn_careCameraTemplate_Click(object sender, EventArgs e)
{
if (MessageBox.Show(crc.GetString("Res0189.f7b0ab1c", "重新获取标定图像前,请确保皮带线上没有任何料盘, 光照水平与正常工作时一致"), crc.GetString("Res0190.43d586cd", "请确认"), MessageBoxButtons.OKCancel) != DialogResult.OK)
return;
if (CameraReelCheck.List.All(x =>
{
return x.SaveBackgroundTemplate();
}))
{
MessageBox.Show(crc.GetString("Res0191.3b108349", "保存成功"));
}
else
{
MessageBox.Show(crc.GetString("Res0192.5c88558f", "标定失败"));
}
}
//private void button2_Click(object sender, EventArgs e) //private void button2_Click(object sender, EventArgs e)
//{ //{
......
...@@ -503,4 +503,9 @@ Clamping_Relax 夹爪气缸放松 Gripper cylinder release ...@@ -503,4 +503,9 @@ Clamping_Relax 夹爪气缸放松 Gripper cylinder release
StringPosChecker_Home 上料定位旋转气缸避让 Avoidance of feeding positioning rotary cylinder StringPosChecker_Home 上料定位旋转气缸避让 Avoidance of feeding positioning rotary cylinder
StringDoor_Axis_Break 上料机构折叠门刹车解除 Brake release of feeding mechanism folding door StringDoor_Axis_Break 上料机构折叠门刹车解除 Brake release of feeding mechanism folding door
StringDoor_Close 上料机构折叠门关闭端 Closing end of feeding mechanism folding door StringDoor_Close 上料机构折叠门关闭端 Closing end of feeding mechanism folding door
timeout 超时 Timeout
\ No newline at end of file \ No newline at end of file
timeout 超时 Timeout
Form1_tabc_tab_setting__SettingControl_btn_careCameraTemplate_Text 保存料盘检测背景模版 Save Tray Inspection Background Template
Res0191.3b108349 保存成功 Save successful
Res0192.5c88558f 标定失败 Calibration failed
Res0189.f7b0ab1c 重新获取标定图像前,请确保皮带线上没有任何料盘, 光照水平与正常工作时一致 Before reacquiring the calibration image, make sure that there are no trays on the belt line and that the light level is the same as in normal operation.
Res0190.43d586cd 请确认 Make sure
\ No newline at end of file \ No newline at end of file
...@@ -499,4 +499,9 @@ Clamping_Relax 夹爪气缸放松 グリッパーシリンダーリリース ...@@ -499,4 +499,9 @@ Clamping_Relax 夹爪气缸放松 グリッパーシリンダーリリース
StringPosChecker_Home 上料定位旋转气缸避让 上料位置決め回転シリンダー回避 StringPosChecker_Home 上料定位旋转气缸避让 上料位置決め回転シリンダー回避
StringDoor_Axis_Break 上料机构折叠门刹车解除 上料機構折りたたみドアブレーキ解除 StringDoor_Axis_Break 上料机构折叠门刹车解除 上料機構折りたたみドアブレーキ解除
StringDoor_Close 上料机构折叠门关闭端 上料機構折りたたみドア閉鎖端 StringDoor_Close 上料机构折叠门关闭端 上料機構折りたたみドア閉鎖端
timeout 超时 タイムアウト
\ No newline at end of file \ No newline at end of file
timeout 超时 タイムアウト
Form1_tabc_tab_setting__SettingControl_btn_careCameraTemplate_Text 保存料盘检测背景模版 キャリア基板検出用背景テンプレートを保存
Res0191.3b108349 保存成功 保存しました
Res0192.5c88558f 标定失败 キャリブレーション失敗
Res0189.f7b0ab1c 重新获取标定图像前,请确保皮带线上没有任何料盘, 光照水平与正常工作时一致 再びキャリブレーション画像を取得する前に、コンベアベルト上にキャリア基板が全くないことを確認してください。また、照明条件は通常の稼働時と同一である必要があります。
Res0190.43d586cd 请确认 確認してください
\ No newline at end of file \ No newline at end of file
...@@ -503,4 +503,9 @@ Clamping_Relax 夹爪气缸放松 ...@@ -503,4 +503,9 @@ Clamping_Relax 夹爪气缸放松
StringPosChecker_Home 上料定位旋转气缸避让 StringPosChecker_Home 上料定位旋转气缸避让
StringDoor_Axis_Break 上料机构折叠门刹车解除 StringDoor_Axis_Break 上料机构折叠门刹车解除
StringDoor_Close 上料机构折叠门关闭端 StringDoor_Close 上料机构折叠门关闭端
timeout 超时
\ No newline at end of file \ No newline at end of file
timeout 超时
Form1_tabc_tab_setting__SettingControl_btn_careCameraTemplate_Text 保存料盘检测背景模版 保存料盘检测背景模版
Res0191.3b108349 保存成功 保存成功
Res0192.5c88558f 标定失败 标定失败
Res0189.f7b0ab1c 重新获取标定图像前,请确保皮带线上没有任何料盘, 光照水平与正常工作时一致 重新获取标定图像前,请确保皮带线上没有任何料盘, 光照水平与正常工作时一致
Res0190.43d586cd 请确认 请确认
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!