6 Commits

9 changed files with 1221 additions and 799 deletions

View File

@ -1,10 +1,12 @@
using OpenCvSharp;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size;
@ -14,7 +16,6 @@ namespace HisenceYoloDetection
{
public static class CheckDiffSciHelper
{
/// <summary>
///
/// </summary>
@ -22,9 +23,9 @@ namespace HisenceYoloDetection
/// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</param>
public static bool CheckDiffSci(string path1, Mat MatDet,Rect sqlrect,Rect detrect, bool IfWhiteWord, string saveDir)
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
{
// 读取和处理第一张图片
// 读取和处理第一张图片。。
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
if (img1.Empty())
{
@ -36,7 +37,7 @@ namespace HisenceYoloDetection
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
Mat thr1 = new Mat();
if(IfWhiteWord)
if (IfWhiteWord)
{
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
}
@ -68,13 +69,13 @@ namespace HisenceYoloDetection
{
Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
}
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
//Rect area2 = new Rect(148,30,229,222);
sqlrect.Width += 20;
sqlrect.Height += 60;
detrect.Width += 20;
detrect.Height += 60;
Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord)
{
@ -95,17 +96,17 @@ namespace HisenceYoloDetection
}
Cv2.Resize(thr1, thr1, new Size(550, 270));
Cv2.Resize(thr2, thr2, new Size(550, 270));
DateTime dt= DateTime.Now;
string filename= dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
DateTime dt = DateTime.Now;
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr1.png");
// 保存结果
//string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
//// 保存结果
Cv2.ImWrite(savePath4, thr1);
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png");
// 保存结果
//Cv2.ImWrite(savePath4, thr1);
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
//// 保存结果
Cv2.ImWrite(savePath3, thr2);
//Cv2.ImWrite(savePath3, thr2);
// 创建卷积核
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
@ -145,10 +146,17 @@ namespace HisenceYoloDetection
Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, devIMG_);
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
//// 保存结果
//Cv2.ImWrite(savePathd, devIMG);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
//// 保存结果
//Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG, devIMG, 20, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 20, 255, ThresholdTypes.Binary);
// 结合差异
Mat sumIMG = new Mat();
@ -159,6 +167,240 @@ namespace HisenceYoloDetection
Mat blackhatImg = new Mat();
Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
// 处理轮廓和保存结果
Point[][] contours = new Point[10000][];
Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
bool isMatch = true;
foreach (var contour in contours)
{
if (Cv2.ContourArea(contour) <= 500)
{
Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
// 框选轮廓
string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath, blackhatImg);
}
else
{
Rect boundingRect = Cv2.BoundingRect(contour);
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
isMatch = false;
string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ok", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ok", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath, blackhatImg);
}
}
return isMatch;
}
public static Rect strChangeRect(string strrect)
{
if (!string.IsNullOrEmpty(strrect))
{
string[] rectstr = strrect.Split(",");
int areaX = int.Parse(rectstr[0]);
int areaY = int.Parse(rectstr[1]);
int areaWidth = int.Parse(rectstr[2]);
int areaHeight = int.Parse(rectstr[3]);
Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight);
return rect;
}
else
{
return new Rect(0, 0, 0, 0);
}
}
public static string rectChangeStr(Rect area)
{
string[] rectsql = new string[4];
rectsql[0] = Convert.ToString(area.X);
rectsql[1] = Convert.ToString(area.Y);
rectsql[2] = Convert.ToString(area.Width);
rectsql[3] = Convert.ToString(area.Height);
string strrect = rectsql.Join(",");
return strrect;
}
public static class CheckDiffSciHelper1
{
/// <summary>
///
/// </summary>
/// <param name="path1">标准图像</param>
/// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</param>
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
{
// 读取和处理第一张图片
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
if (img1.Empty())
{
Console.WriteLine($"Error loading image {path1}");
return false;
}
// Cv2.Resize(img1, img1, new Size(550, 270));
Mat gimg1 = new Mat();
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
Mat thr1 = new Mat();
if (IfWhiteWord)
{
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
}
else
{
Cv2.Threshold(gimg1, thr1, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu
}
// 读取和处理第二张图片
Mat img2 = MatDet.Clone();
if (img2.Empty())
{
// Console.WriteLine($"Error loading image {path2}");
return false;
}
// Cv2.Resize(img2, img2, new Size(550, 270));
Mat gimg2 = new Mat();
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
Mat thr2 = new Mat();
//Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
if (IfWhiteWord)
{
Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
}
else
{
Cv2.Threshold(gimg2, thr2, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu
}
//Rect area2 = new Rect(148,30,229,222);
sqlrect.Width += 20;
sqlrect.Height += 20;
detrect.Width += 20;
detrect.Height += 20;
Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord)
{
matCutblack1.SetTo(Scalar.Black);
}
else
{
matCutblack1.SetTo(Scalar.Black);
}
Mat matCutblack2 = new Mat(thr2, detrect);
if (IfWhiteWord)
{
matCutblack2.SetTo(Scalar.Black);
}
else
{
matCutblack2.SetTo(Scalar.Black);
}
Cv2.Resize(thr1, thr1, new Size(845, 498));
Cv2.Resize(thr2, thr2, new Size(845, 498));
DateTime dt = DateTime.Now;
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
//string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
//// 保存结果
//Cv2.ImWrite(savePath4, thr1);
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
//// 保存结果
//Cv2.ImWrite(savePath3, thr2);
// 创建卷积核
Mat filter1 = new Mat(15,15, MatType.CV_32F, new Scalar(0));
filter1.Row(7).SetTo(new Scalar(0.025));
filter1.Col(7).SetTo(new Scalar(0.025));
// 应用卷积
Mat final_result1 = new Mat();
Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result1, final_result1, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Mat final_result2 = new Mat();
Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result2, final_result2, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//裁剪才行
//string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result1.png");
//// 保存结果
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
//Cv2.ImWrite(savePath2, final_result1);
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result2.png");
//// 保存结果
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
//Cv2.ImWrite(savePath, final_result2);
// 计算图像差异
Mat devIMG = new Mat();
Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, devIMG_);
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
//// 保存结果
//Cv2.ImWrite(savePathd, devIMG);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
//// 保存结果
//Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 45, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 45, 255, ThresholdTypes.Binary);
// 结合差异
Mat sumIMG = new Mat();
Cv2.Add(devIMG, devIMG_, sumIMG);
//string savePaths = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "sumIMG.png");
//// 保存结果
//Cv2.ImWrite(savePaths, sumIMG);
// 应用形态学操作
Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
Mat blackhatImg = new Mat();
Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
// 处理轮廓和保存结果
Point[][] contours = new Point[10000][];
Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
@ -175,168 +417,20 @@ namespace HisenceYoloDetection
{
Rect boundingRect = Cv2.BoundingRect(contour);
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
isMatch= false;
isMatch = false;
}
}
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_Rect.png");
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_diff.png");
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath, blackhatImg);
return isMatch;
}
public static Rect strChangeRect(string strrect)
{
if (!string.IsNullOrEmpty(strrect))
{
string[] rectstr = strrect.Split(",");
int areaX = int.Parse(rectstr[0]);
int areaY = int.Parse(rectstr[1]);
int areaWidth = int.Parse(rectstr[2]);
int areaHeight = int.Parse(rectstr[3]);
Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight);
return rect;
}else
{
return new Rect(0,0,0, 0);
}
}
public static string rectChangeStr(Rect area)
{
string[] rectsql = new string[4];
rectsql[0] = Convert.ToString(area.X);
rectsql[1] = Convert.ToString(area.Y);
rectsql[2] = Convert.ToString(area.Width);
rectsql[3] = Convert.ToString(area.Height);
string strrect = rectsql.Join(",");
return strrect;
}
//public static void CheckDiffSci(string path1, string path2, bool IfWhiteWord, string saveDir)
//{
// // 读取和处理第一张图片
// Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
// if (img1.Empty())
// {
// Console.WriteLine($"Error loading image {path1}");
// return;
// }
// Cv2.Resize(img1, img1, new Size(550, 270));
// Mat gimg1 = new Mat();
// Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
// Mat thr1 = new Mat();
// if (IfWhiteWord)
// {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// }
// else
// {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// }
// string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr1.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath4, thr1);
// // 读取和处理第二张图片
// Mat img2 = Cv2.ImRead(path2, ImreadModes.Color);
// if (img2.Empty())
// {
// Console.WriteLine($"Error loading image {path2}");
// return;
// }
// Cv2.Resize(img2, img2, new Size(550, 270));
// Mat gimg2 = new Mat();
// Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
// Mat thr2 = new Mat();
// //Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// if (IfWhiteWord)
// {
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// }
// else
// {
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// }
// // Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr2.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath3, thr2);
// // 创建卷积核
// Mat filter1 = new Mat(17, 17, MatType.CV_32F, new Scalar(0));
// filter1.Row(8).SetTo(new Scalar(0.025));
// filter1.Col(8).SetTo(new Scalar(0.025));
// // 应用卷积
// Mat final_result1 = new Mat();
// Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Mat final_result2 = new Mat();
// Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// // 计算图像差异
// Mat devIMG = new Mat();
// Mat devIMG_ = new Mat();
// Cv2.Subtract(final_result1, final_result2, devIMG);
// Cv2.Subtract(final_result2, final_result1, devIMG_);
// // 对差异图像应用阈值
// Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary);
// Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary);
// // 结合差异
// Mat sumIMG = new Mat();
// Cv2.Add(devIMG, devIMG_, sumIMG);
// // 应用形态学操作
// Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
// Mat blackhatImg = new Mat();
// Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
// // 处理轮廓和保存结果
// Point[][] contours = new Point[10000][];
// Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
// foreach (var contour in contours)
// {
// if (Cv2.ContourArea(contour) <= 100)
// {
// Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
// // 框选轮廓
// }
// else
// {
// Rect boundingRect = Cv2.BoundingRect(contour);
// Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
// }
// }
// string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_Rect.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath2, img2);
// string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath, blackhatImg);
//}
}
}

View File

@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="MainForm.resx~RF4efdcc4.TMP" />
<None Remove="ManagerModelHelper.cs~RF97ff9f.TMP" />
<None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" />
</ItemGroup>

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ using OpenCvSharp.Dnn;
using OpenCvSharp.Extensions;
using OpenCvSharp.XFeatures2D;
using Sunny.UI;
using Sunny.UI.Win32;
using System;
using System.ComponentModel;
using System.Data;
@ -21,9 +22,11 @@ using System.Net;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using XKRS.Device.SimboVision.SimboHelper;
using XKRS.UI;
using static HisenceYoloDetection.CheckDiffSciHelper;
using static HisenceYoloDetection.MainForm;
using static System.Runtime.InteropServices.JavaScript.JSType;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
@ -62,6 +65,9 @@ namespace HisenceYoloDetection
List<XKHisence> xKHisences = new List<XKHisence>();
static AutoResetEvent myResetEvent = new AutoResetEvent(false);
AutoResetEvent _runHandleBefore = new AutoResetEvent(false);
ManualResetEvent _runHandleAfter = new ManualResetEvent(false);
bool PLC545 = false;
bool PLC548 = false;
@ -101,7 +107,11 @@ namespace HisenceYoloDetection
string Cam1OnePath = "";
string Cam1TwoPath = "";
string ModelChangePath = "";
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string GreenLightingAdress = "";
string YellowLightingAdress = "";
string RedLightingAdress = "";
string WaringAdress = "";
/// <summary>
/// <20><EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
/// </summary>
@ -189,11 +199,25 @@ namespace HisenceYoloDetection
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
string s1 = "0##Ec04060##20<32><30>##Rapide15mns";
string s2 = "ECO4060##20<32><30>C##Rapide15mns";
bool st = ManagerModelHelper.StrMatch2(s1, s2);
if (_runHandleBefore == null)
{
_runHandleBefore = new AutoResetEvent(false);
}
if (_runHandleAfter == null)
{
_runHandleAfter = new ManualResetEvent(false);
}
string s1 = "gorenjeSTEAMTECHSNOWFLAKEDRUM65kg";
string s2 = "STEAMTECHSNOWFLAKEDRUM65kg";
bool st = ManagerModelHelper.StrMatch(s1, s2);
bool st1 = ManagerModelHelper.StrMatch2(s1, s2);
//Rect rect = new Rect(0, 0, 0, 0);
//string path2 = "D:\\Hisence\\SQLImages\\W80WXWJ060539V0WW80WX120293\\2\\W80WXWJ060539V0WW80WX120293result.jpg";
@ -265,6 +289,8 @@ namespace HisenceYoloDetection
OnSpeedShow();//<2F>߳̿<DFB3><CCBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>ʾ<EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>
OnPostionShow();//<2F>߳̿<DFB3><CCBF><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>ʾ<EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//<2F>Ƶ<EFBFBD>
//t = new System.Timers.Timer(10000);//ʵ<><CAB5><EFBFBD><EFBFBD>Timer<65><EFBFBD><E0A3AC><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>ʱ<EFBFBD><CAB1>Ϊ10000<30><30><EFBFBD>
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ִ<EFBFBD><D6B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
//t.AutoReset = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>һ<EFBFBD>Σ<EFBFBD>false<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֱִ<D6B1><D6B4>(true)<29><>
@ -274,6 +300,7 @@ namespace HisenceYoloDetection
}
public void Execute(object source, System.Timers.ElapsedEventArgs e)
{
t.Stop(); //<2F>ȹرն<D8B1>ʱ<EFBFBD><CAB1>
//melsecPLCTCPDriver.WriteInt("548", 1);
//Thread.Sleep(1000);
@ -521,6 +548,7 @@ namespace HisenceYoloDetection
// tbFrameRate.Enabled = false;
bnGetParam.Enabled = false;
bnSetParam.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
@ -594,10 +622,10 @@ namespace HisenceYoloDetection
melsecPLCTCPDriver.WriteInt("514", 0);//<2F><>λ<EFBFBD>ɿ<EFBFBD>
melsecPLCTCPDriver.WriteInt("524", 0);//<2F><>λ<EFBFBD>ɿ<EFBFBD>
melsecPLCTCPDriver.WriteInt("406", 60000); //д<><D0B4><EFBFBD>ֶ<EFBFBD><D6B6>ٶ<EFBFBD>
melsecPLCTCPDriver.WriteInt("416", 8000);
melsecPLCTCPDriver.WriteInt("416", 10000);
melsecPLCTCPDriver.WriteInt("426", 10000);
melsecPLCTCPDriver.WriteInt("404", 100000); //д<>붨λ<EBB6A8>ٶ<EFBFBD>
melsecPLCTCPDriver.WriteInt("414", 8000);
melsecPLCTCPDriver.WriteInt("414", 10000);
melsecPLCTCPDriver.WriteInt("424", 10000);
@ -612,6 +640,7 @@ namespace HisenceYoloDetection
Thread.Sleep(200);
melsecPLCTCPDriver.WriteInt("580", 0);
Thread.Sleep(200);
melsecPLCTCPDriver.WriteInt("550", 0);
while (true)
{
int IfXZeros = melsecPLCTCPDriver.ReadInt("102");
@ -977,11 +1006,12 @@ namespace HisenceYoloDetection
}
if (iNum1 >= 2)
{
if (bBar)
{
_runHandleBefore.WaitOne();
bBarTriger = true;//<2F>޸ij<DEB8><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD>ȡ<EFBFBD>ͺ<EFBFBD>
Cam2.SnapshotCount = 0;
Cam2.Snapshot();
xKNow = GetModeFromBar("VWJ070633V0WW80F0120356");//<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
//xKNow = GetModeFromBar(m_sKEYENCEBar);//<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
@ -1039,6 +1069,7 @@ namespace HisenceYoloDetection
#endregion
int YPos = 8715;
int ZPos = 25000;
bool StopM = false;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>źŵ<C5BA>
/// <summary>
/// <20><><EFBFBD><EFBFBD>ϴ<EFBFBD>»<EFBFBD>544<34>Ƿ񴥷<C7B7><F1B4A5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B4AB><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
/// </summary>
@ -1081,13 +1112,21 @@ namespace HisenceYoloDetection
else
{
iNum1 = 0;
melsecPLCTCPDriver.WriteInt("550", 1);//<2F><><EFBFBD><EFBFBD>
}
if (iNum1 >= 2)
{
//if (bBarTriger)
{
#if true
#if false
if (!StopM)
{
melsecPLCTCPDriver.WriteInt("550", 1);//<2F><><EFBFBD><EFBFBD>
StopM = true;
}
myLog("<22><>һ<EFBFBD>βɼ<CEB2>ͼ<EFBFBD><CDBC>", DateTime.Now);
//<2F>ƶ<EFBFBD>ģ<EFBFBD><C4A3> <20><><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ <20><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ǰ<EFBFBD>ƶ<EFBFBD>
MoveToP(5815, YPos, ZPos);
@ -1108,7 +1147,7 @@ namespace HisenceYoloDetection
double disreal = average * (-0.54054) + 1324.3232;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><>ƶ<EFBFBD><C6B6>ľ<EFBFBD><C4BE><EFBFBD>
double dismove = disreal - 876;
if (dismove > 0 && dismove < 4000)
if (dismove > -4000 && dismove < 4000)
{
MoveToP(5815, YPos, ZPos + (int)(dismove));
}
@ -1120,15 +1159,18 @@ namespace HisenceYoloDetection
Cam2.SnapshotCount = 0;
Cam2.Snapshot();
myLog("<22>ڶ<EFBFBD><DAB6>βɼ<CEB2>ͼ<EFBFBD><CDBC>", DateTime.Now);
//if (xKNow != null)
//{
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
//}
//currentXP = 54964;
//Thread.Sleep(2000);//ɾ
MoveToP(51043, YPos, ZPos + (int)(dismove));
Cam1.Snapshot();
MoveToP(5815, YPos, ZPos);
melsecPLCTCPDriver.WriteInt("550", 0);//<2F><><EFBFBD><EFBFBD>
//Thread.Sleep(300);//ϴ<>»<EFBFBD><C2BB><EFBFBD><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD>ȥ
//if (xKNow != null)
//{
// MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);
@ -1259,8 +1301,8 @@ namespace HisenceYoloDetection
{
//Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\<5C><><EFBFBD><EFBFBD>\\1\\001.jpg"); ;
Cam1ImgOne = cameraMat;
Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\<5C><><EFBFBD><EFBFBD>\\1\\001.jpg"); ;
//Cam1ImgOne = cameraMat;
IfCam1OneTriger = true;
originMatShow.Image = cameraMat.ToBitmap();
//pictureBox1.Image = cameraMat.ToBitmap();
@ -1270,13 +1312,13 @@ namespace HisenceYoloDetection
//<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (SnapshotCount == 2)
{
// Mat mat = Cv2.ImRead("D:\\Hisence\\<5C><><EFBFBD><EFBFBD>\\1\\002.jpg");
// Cam1ImgTwo = mat;
Cam1ImgTwo = cameraMat;
Cam1ImgTwo = Cv2.ImRead("D:\\Hisence\\<5C><><EFBFBD><EFBFBD>\\1\\002.jpg");
//Cam1ImgTwo = cameraMat;
IfCam1TwoTriger = true;
originMatShow2.Image = cameraMat.ToBitmap();
_runHandleAfter.Set();
}
@ -1302,8 +1344,9 @@ namespace HisenceYoloDetection
// Mat mat = Cv2.ImRead("F:\\<5C><><EFBFBD><EFBFBD>ϴ<EFBFBD>»<EFBFBD>\\cam1\\2024517161641.jpg");
Cam2ImgShowBar = cameraMat;
IfCam2Triger = true;
originMat2Show.Image = cameraMat.ToBitmap();
originMat2Show.Image = cameraMat.ToBitmap();
//_runHandleAfter.Set();
// CamShow2.ImaMAt = cameraMat;
cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
@ -1311,6 +1354,7 @@ namespace HisenceYoloDetection
public volatile int AllDsums = 0;
public volatile int NGDsums = 0;
public volatile int OKDsums = 0;
public volatile int WUsums = 0;
/// <summary>
/// <20><>ʼʶ<CABC><CAB6>
/// </summary>
@ -1323,6 +1367,8 @@ namespace HisenceYoloDetection
{
try
{
//<2F>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ʹ<><EFBFBD><E4B2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӻ<EFBFBD><D3BA><EFBFBD>˸
_runHandleAfter.WaitOne();
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (IfCam2Triger)
{
@ -1342,6 +1388,7 @@ namespace HisenceYoloDetection
sw.WriteLine(IOcrBAr + "\n");
sw.Flush();
}
// IOcrBAr = "BatchW9659ModelWNHPI74SCPSDE";
IOcrBAr = "W821PWMS27106WD2";
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ȶ<EFBFBD>
xKNow = GetModeFromBar(IOcrBAr);//<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
@ -1387,8 +1434,11 @@ namespace HisenceYoloDetection
}
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (IfCam1TwoTriger && bBarTriger)
// if (IfCam1TwoTriger && bBarTriger)
{
IfCam1TwoTriger = false;
bBarTriger = false;
_runHandleAfter.Reset();
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
Defet_OnDetectionDone(whiteMat, 1);
Defet_OnDetectionDone(whiteMat, 2);
@ -1398,7 +1448,6 @@ namespace HisenceYoloDetection
Defet_OnDetectionDone(whiteMat, 6);
Defet_OnDetectionDone(whiteMat, 7);
XK_HisenceWord xK_MatchDet = new XK_HisenceWord();
xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
AllDsums++;
@ -1420,19 +1469,14 @@ namespace HisenceYoloDetection
List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = req.currentMat.Clone();
Mat mCut = new Mat();
Stopwatch sw = new Stopwatch();
sw.Start();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
InsertSqlRunDataButton(ref keyValueResult, false, ref mCut, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
sw.Stop();
myLog("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>" + sw.ElapsedMilliseconds, DateTime.Now);
if (mL.ResultMap != null)
{
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
ResultMatShow.Image = mL.ResultMap;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MLRequest req2 = new MLRequest();
req2.currentMat = Cam1ImgTwo;
@ -1444,18 +1488,18 @@ namespace HisenceYoloDetection
req2.iouThreshold = 0.4f;//<2F><><EFBFBD><EFBFBD>IOU
req2.out_node_name = "output";
MLResult mL2 = simboObjectDetection.RunInferenceFixed(req2);
List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>();
Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
if (mL2.ResultMap != null)
{
mL2.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
ResultMatShow2.Image = mL2.ResultMap;
}
List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>();
Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
#region <EFBFBD><EFBFBD>ִ<EFBFBD>ж<EFBFBD>λ<EFBFBD>ȶ<EFBFBD>
//ִ<>ж<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string[] listLabels = xKNow.Detect.Split(",");
@ -1483,6 +1527,25 @@ namespace HisenceYoloDetection
HashSet<string> set1 = new HashSet<string>(listLabels);
HashSet<string> set2 = new HashSet<string>(RealLabels);
bool MatchStr = set1.SetEquals(set2);
#endregion
//<2F><><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ȶ<EFBFBD>
if (MatchStr)
{
//Mat mCut = new Mat();
Stopwatch sw = new Stopwatch();
sw.Start();
InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop();
myLog("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>" + sw.ElapsedMilliseconds, DateTime.Now);
}
if (MatchStr)
{
@ -1499,11 +1562,9 @@ namespace HisenceYoloDetection
// int sqlblocksum=
IfCam1TwoTriger = false;
bBarTriger = false;
melsecPLCTCPDriver.WriteInt("550", 0);//<2F><><EFBFBD><EFBFBD>
if (MatchStr)
{
OKDsums++;
@ -1519,14 +1580,39 @@ namespace HisenceYoloDetection
}
else
{
NGDsums++;
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//<2F><><EFBFBD><EFBFBD>
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//<2F><><EFBFBD><EFBFBD>
myLog(<><C6A5>ʧ<EFBFBD><CAA7>", DateTime.Now);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
// InsertXK_HisenceWordMatchData(xK_MatchDet, false);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ж<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>NGϴ<EFBFBD>»<EFBFBD>
DialogResult dr = MessageBox.Show("<22>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>죿", "<22>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//<2F><><EFBFBD><EFBFBD>
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//<2F><><EFBFBD><EFBFBD>
OKDsums++;
WUsums++;
this.Invoke(new Action(() =>
{
double percent = (double)WUsums/ AllDsums;
string percentText = percent.ToString("0.0%");//<2F><><EFBFBD><EFBFBD>percentText<78><74>ֵΪ10.0%
textBox1.Text = percentText;
OKOrNGShow.Image = OKbitmap;
}));
}
else
{
NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//<2F><><EFBFBD><EFBFBD>
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//<2F><><EFBFBD><EFBFBD>
this.Invoke(new Action(() =>
{
OKOrNGShow.Image = NGbitmap;
}));
}
}
@ -1535,7 +1621,7 @@ namespace HisenceYoloDetection
}
catch (Exception e)
{
throw e;
}
finally
{
@ -1615,7 +1701,7 @@ namespace HisenceYoloDetection
{
m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data);
// myLog("<22>ͺ<EFBFBD>Ocr" + m_sKEYENCEBar, DateTime.Now);
_runHandleBefore.Set();
bBar = true;
}
@ -1795,7 +1881,26 @@ namespace HisenceYoloDetection
private void StartDecBtn_Click(object sender, EventArgs e)
{
/*
string path22 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628924614_Rect.png";
Mat pathmat2 = Cv2.ImRead(path22);
string path222 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628923102_Rect.png";
Rect rect1 = new Rect(1929, 745, 396, 377);
Rect rect = new Rect(368, 53, 396, 377);
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
string path = "D:\\Hisence\\Test1\\1.png";
Mat pathmat =Cv2.ImRead(path);
string path2 = "D:\\Hisence\\Test1\\2.png";
Rect rect2 = new Rect(0, 0, 0, 0);
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
*/
//OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//<2F>Ƶ<EFBFBD>
TriggerCameral2();
ReadyDetect();
myLog("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳ɹ<CCB3>", DateTime.Now);
@ -2193,9 +2298,9 @@ namespace HisenceYoloDetection
List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = CamOneI.currentMat.Clone();
Mat mCut = new Mat();
//Mat mCut = new Mat();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
InsertSqlRunDataButton(ref keyValueResult, true, ref mCut, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
InsertSqlRunDataButton(ref keyValueResult, true, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
@ -2599,37 +2704,37 @@ namespace HisenceYoloDetection
{
case 1:
{
DefetShow1.ImaMAt = detectionImage;
canvas1.ImaMAt = detectionImage;
}
break;
case 2:
{
DefetShow2.ImaMAt = detectionImage;
canvas2.ImaMAt = detectionImage;
}
break;
case 3:
{
DefetShow3.ImaMAt = detectionImage;
canvas3.ImaMAt = detectionImage;
}
break;
case 4:
{
DefetShow4.ImaMAt = detectionImage;
canvas4.ImaMAt = detectionImage;
}
break;
case 5:
{
DefetShow5.ImaMAt = detectionImage;
canvas5.ImaMAt = detectionImage;
}
break;
case 6:
{
DefetShow6.ImaMAt = detectionImage;
canvas6.ImaMAt = detectionImage;
}
break;
case 7:
{
DefetShow7.ImaMAt = detectionImage;
// canvas7.ImaMAt = detectionImage;
}
break;
case 8:
@ -2659,7 +2764,7 @@ namespace HisenceYoloDetection
/// <param name="strMatList"><3E><><EFBFBD>صĶ<D8B5>λ<EFBFBD><CEBB><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD></param>
/// <param name="strMatRefList"></param>
/// <param name="IOcrModel"></param>
public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat CutMat, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
{
#if true
//try
@ -2777,6 +2882,7 @@ namespace HisenceYoloDetection
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCuti, area);
Stopwatch sw = new Stopwatch();
sw.Start();
//OCRʶ<52><CAB6><EFBFBD>ü<EFBFBD>ͼƬ
@ -2858,6 +2964,7 @@ namespace HisenceYoloDetection
string TextWoidStr = OcrFuzzyTextInsert.Join("##"); //ʵ<>ʵļ<CAB5><C4BC><EFBFBD><EFBFBD><EFBFBD>
string SQLStr = "";//<2F><>־<EFBFBD><D6BE>ʾ<EFBFBD><CABE><EFBFBD>ݿ<EFBFBD><DDBF>Ĺؼ<C4B9><D8BC><EFBFBD>
bool juanjiMatch = false;
string filenameone = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
switch (blockIndex)
{
case "1"://<2F><>ȫƥ<C8AB><C6A5> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
@ -2865,19 +2972,31 @@ namespace HisenceYoloDetection
xK_HisenceWord.OneblockPath = CutSavePath;
xK_HisenceWord.OneblockMainWord = MainWoidStr;
xK_HisenceWord.OneblockText = TextWoidStr;
SQLStr = SQlxK_HisenceWord.OneblockMainWord;
SQLStr = SQlxK_HisenceWord.OneblockText;
string SQLStr2 = SQlxK_HisenceWord.OneblockMainWord;
if (!saveimage)
{
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr);
if (!OneIF)
bool ssD = ManagerModelHelper.StrMatch(SQLStr, xK_HisenceWord.OneblockText);
Console.Write(SQLStr);
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr2);
if (!OneIF1 || !ssD)
{
OneIF = false;
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
DisplayResult(mLcut);
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 1);
string Path_1 = Path.Combine("D:\\Hisence\\Test\\1\\ng", filenameone + "_res.png");
Cv2.ImWrite(Path_1, mLcut.ResultMap.ToMat());
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 1);
string Path_2 = Path.Combine("D:\\Hisence\\Test\\1\\ok", filenameone + "_res.png");
Cv2.ImWrite(Path_2, OKMat);
}
}
@ -2927,16 +3046,26 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.ThreeblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.ThreeblockPath;
juanjiMatch = CheckDiffSciHelper1.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test1");
if (!OneIF1 || !juanjiMatch)
{
OneIF = true;//<2F><><EFBFBD>޸<EFBFBD>6.28
/*
DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 3);
*/
Defet_OnDetectionDone(OKMat, 3);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 3);
}
@ -2951,9 +3080,15 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.FourblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.FourblockPath;
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
@ -2961,6 +3096,7 @@ namespace HisenceYoloDetection
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 4);
}
@ -2975,9 +3111,14 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.FiveblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.FiveblockMainWord;
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
@ -2985,6 +3126,7 @@ namespace HisenceYoloDetection
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 5);
}
}
@ -2998,9 +3140,16 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.SixblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.SixblockPath;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֱΪtrue
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
juanjiMatch = true;
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
// DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
@ -3008,6 +3157,7 @@ namespace HisenceYoloDetection
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 6);
}
@ -3022,9 +3172,14 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.SevenblockPath;
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
//DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
@ -3032,6 +3187,7 @@ namespace HisenceYoloDetection
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 7);
}
}
@ -3045,9 +3201,14 @@ namespace HisenceYoloDetection
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.EightblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord);
if (!OneIF)
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.EightblockPath;
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
{
OneIF = false;
// DisplayResult(mLcut);
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD>
// mLcut.ResultMap;
@ -3055,6 +3216,7 @@ namespace HisenceYoloDetection
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 8);
}
}
@ -3067,10 +3229,7 @@ namespace HisenceYoloDetection
using (StreamWriter sw = new StreamWriter(txtLog, true))
{
if (blockIndex == "2")
{
sw.WriteLine("<22><><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>" + juanjiMatch);
}
sw.WriteLine("<22><>" + blockIndex + "<22><><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>" + juanjiMatch);
sw.WriteLine("<22><>" + blockIndex + "<22><><EFBFBD>ݿ<EFBFBD>" + SQLStr + "<22>ؼ<EFBFBD><D8BC><EFBFBD>" + MainWoidStr + "<22><><EFBFBD><EFBFBD>" + OneIF + "\n");
sw.WriteLine("<22><>" + blockIndex + " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + TextWoidStr + "\n");
@ -3122,5 +3281,20 @@ namespace HisenceYoloDetection
myLog("X<><58>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>", DateTime.Now);
}
}
private void handStopBtn_Click(object sender, EventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 1);
}
private void HandRuningBtn_Click(object sender, EventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 0);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 0);
}
}
}

View File

@ -142,7 +142,7 @@
<value>733, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>34</value>
<value>25</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@ -189,7 +189,7 @@ namespace HisenceYoloDetection
// 计算相似度相似度等于1减去标准化的Levenshtein距离
double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length));
bool areEqual = false;
if (similarity < 0.5)
if (similarity < 0.9)
{
areEqual = false;
}

View File

@ -11,7 +11,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver
public class MelsecPLCTCPDriver1
{
private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();

View File

@ -12,7 +12,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver1
public class MelsecPLCTCPDriver
{
// private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();

View File

@ -399,6 +399,7 @@ namespace XKRS.UI
}
#endregion
#region
GPathList.ForEach(path =>
{