diff --git a/HisenceYoloDetection/CheckDiffSciHelper.cs b/HisenceYoloDetection/CheckDiffSciHelper.cs index 40944c7..38cfc5e 100644 --- a/HisenceYoloDetection/CheckDiffSciHelper.cs +++ b/HisenceYoloDetection/CheckDiffSciHelper.cs @@ -1,4 +1,5 @@ using OpenCvSharp; +using Sunny.UI.Win32; using System; using System.Collections.Generic; using System.Linq; @@ -12,9 +13,8 @@ using Size = OpenCvSharp.Size; namespace HisenceYoloDetection { - public static class CheckDiffSciHelper + public static class CheckDiffSciHelper { - /// /// /// @@ -31,6 +31,7 @@ namespace HisenceYoloDetection 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(); @@ -44,16 +45,21 @@ namespace HisenceYoloDetection Cv2.Threshold(gimg1, thr1, 0, 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); @@ -63,61 +69,114 @@ namespace HisenceYoloDetection Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu); } - // 裁剪和设置为黑色 - sqlrect.Width += 20; - detrect.Width += 20; - Mat matCutblack1 = new Mat(thr1, sqlrect); - matCutblack1.SetTo(Scalar.Black); - Mat matCutblack2 = new Mat(thr2, detrect); - matCutblack2.SetTo(Scalar.Black); + //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) + { + 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(550, 270)); Cv2.Resize(thr2, thr2, new Size(550, 270)); - DateTime dt = DateTime.Now; - string filename = dt.ToString("yyyyMMddHHmmssfff"); + 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(7, 7, MatType.CV_32F, new Scalar(0.025)); + // 创建卷积核 + 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); + Mat final_result2 = new Mat(); - Cv2.Filter2D(thr1, final_result1, -1, filter1, new Point(-1, -1), 0, BorderTypes.Reflect); - Cv2.Filter2D(thr2, final_result2, -1, filter1, new Point(-1, -1), 0, BorderTypes.Reflect); + 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); + //裁剪才行 + + + //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_); // 对差异图像应用阈值 - double threshold = 20.0; // 调低阈值 - Cv2.Threshold(devIMG, devIMG, threshold, 255, ThresholdTypes.Binary); - Cv2.Threshold(devIMG_, devIMG_, threshold, 255, ThresholdTypes.Binary); + Cv2.Threshold(devIMG, devIMG, 20, 255, ThresholdTypes.Binary); + Cv2.Threshold(devIMG_, devIMG_, 20, 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); // 使用膨胀操作 + Cv2.Dilate(sumIMG, blackhatImg, kernelCL); - // 检测和绘制轮廓 - Point[][] contours; + // 处理轮廓和保存结果 + 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) <= 100) + if (Cv2.ContourArea(contour) <= 500) { Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED); + // 框选轮廓 + } else { @@ -127,16 +186,19 @@ namespace HisenceYoloDetection } } - // 保存最终结果 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(path2) + "_diff.png"); Cv2.ImWrite(savePath, blackhatImg); - return isMatch; } + public static Rect strChangeRect(string strrect) { if (!string.IsNullOrEmpty(strrect)) @@ -149,14 +211,15 @@ namespace HisenceYoloDetection Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight); return rect; - }else - { - return new Rect(0,0,0, 0); } - + else + { + return new Rect(0, 0, 0, 0); + } + } - public static string rectChangeStr(Rect area) + public static string rectChangeStr(Rect area) { string[] rectsql = new string[4]; rectsql[0] = Convert.ToString(area.X); @@ -167,123 +230,198 @@ namespace HisenceYoloDetection 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(); + public static class CheckDiffSciHelper1 + { + /// + /// + /// + /// 标准图像 + /// 要对比的图像 + /// 白板黑字为true + /// 存储路径 + 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, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu); - // } + if (IfWhiteWord) + { + Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu); + } + else + { + Cv2.Threshold(gimg1, thr1, 100, 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 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 + } - // // 创建卷积核 - // 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); + //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(); - // 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); + string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png"); + // 保存结果 - // // 计算图像差异 - // Mat devIMG = new Mat(); - // Mat devIMG_ = new Mat(); - // Cv2.Subtract(final_result1, final_result2, devIMG); - // Cv2.Subtract(final_result2, final_result1, devIMG_); + Cv2.ImWrite(savePath4, thr1); + string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png"); + // 保存结果 - // // 对差异图像应用阈值 - // Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary); - // Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary); + Cv2.ImWrite(savePath3, thr2); - // // 结合差异 - // Mat sumIMG = new Mat(); - // Cv2.Add(devIMG, devIMG_, sumIMG); + // 创建卷积核 + + 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 kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3)); - // Mat blackhatImg = new Mat(); - // Cv2.Dilate(sumIMG, blackhatImg, kernelCL); + + // 应用卷积 + 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); - // // 处理轮廓和保存结果 - // Point[][] contours = new Point[10000][]; - // Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple); + 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); + //裁剪才行 - // 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); - //} + //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); + bool isMatch = true; + 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); + isMatch = false; + } + } + + 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(path2) + "_diff.png"); + Cv2.ImWrite(savePath, blackhatImg); + return isMatch; + } + } } } diff --git a/HisenceYoloDetection/MainForm.Designer.cs b/HisenceYoloDetection/MainForm.Designer.cs index fe114a9..909151c 100644 --- a/HisenceYoloDetection/MainForm.Designer.cs +++ b/HisenceYoloDetection/MainForm.Designer.cs @@ -31,13 +31,13 @@ components = new System.ComponentModel.Container(); OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat(); + OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat(); + OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat(); + OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat6 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat7 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat8 = new OpenCvSharp.Mat(); - OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat9 = new OpenCvSharp.Mat(); - OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat(); - OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); tabPage2 = new TabPage(); panel1 = new Panel(); @@ -75,6 +75,8 @@ label12 = new Label(); label11 = new Label(); ModeleShow = new GroupBox(); + handStopBtn = new Button(); + HandRuningBtn = new Button(); ZBackwardrbx = new RadioButton(); YBackwardrbx = new RadioButton(); XBackwardrbx = new RadioButton(); @@ -128,7 +130,8 @@ tabPage5 = new TabPage(); panel4 = new Panel(); panel5 = new Panel(); - DefetShow5 = new XKRS.UI.Canvas(); + DefetShow7 = new XKRS.UI.Canvas(); + DefetShow6 = new XKRS.UI.Canvas(); panel8 = new Panel(); 实时显示 = new Label(); OKOrNGShow = new PictureBox(); @@ -142,11 +145,12 @@ ScanDevList = new Button(); DevNameCombo = new ComboBox(); InitMachine = new Button(); + DefetShow2 = new XKRS.UI.Canvas(); panel6 = new Panel(); groupBox2 = new GroupBox(); + DefetShow5 = new XKRS.UI.Canvas(); DefetShow4 = new XKRS.UI.Canvas(); DefetShow3 = new XKRS.UI.Canvas(); - DefetShow2 = new XKRS.UI.Canvas(); originMat2Show = new PictureBox(); DefetShow1 = new XKRS.UI.Canvas(); ResultMatShow2 = new PictureBox(); @@ -198,8 +202,6 @@ richTextBox1 = new RichTextBox(); contextMenuStrip1 = new ContextMenuStrip(components); backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); - DefetShow6 = new XKRS.UI.Canvas(); - DefetShow7 = new XKRS.UI.Canvas(); tabPage2.SuspendLayout(); panel1.SuspendLayout(); groupBox5.SuspendLayout(); @@ -563,6 +565,8 @@ // // ModeleShow // + ModeleShow.Controls.Add(handStopBtn); + ModeleShow.Controls.Add(HandRuningBtn); ModeleShow.Controls.Add(ZBackwardrbx); ModeleShow.Controls.Add(YBackwardrbx); ModeleShow.Controls.Add(XBackwardrbx); @@ -582,6 +586,26 @@ ModeleShow.TabStop = false; ModeleShow.Text = "模组显示"; // + // handStopBtn + // + handStopBtn.Location = new Point(266, 266); + handStopBtn.Name = "handStopBtn"; + handStopBtn.Size = new Size(125, 82); + handStopBtn.TabIndex = 23; + handStopBtn.Text = "手动阻塞"; + handStopBtn.UseVisualStyleBackColor = true; + handStopBtn.Click += handStopBtn_Click; + // + // HandRuningBtn + // + HandRuningBtn.Location = new Point(410, 266); + HandRuningBtn.Name = "HandRuningBtn"; + HandRuningBtn.Size = new Size(125, 82); + HandRuningBtn.TabIndex = 22; + HandRuningBtn.Text = "手动放行"; + HandRuningBtn.UseVisualStyleBackColor = true; + HandRuningBtn.Click += HandRuningBtn_Click; + // // ZBackwardrbx // ZBackwardrbx.Appearance = Appearance.Button; @@ -1142,26 +1166,47 @@ panel5.Size = new Size(1276, 762); panel5.TabIndex = 0; // - // DefetShow5 + // DefetShow7 // - DefetShow5.AllowSelectDefect = true; - DefetShow5.BrushColor = null; - DefetShow5.ImagePath = ""; - mat6.IsEnabledDispose = true; - DefetShow5.ImaMAt = mat6; - DefetShow5.ImgData = null; - DefetShow5.Location = new Point(537, 460); - DefetShow5.MoveStep = 5F; - DefetShow5.Name = "DefetShow5"; - DefetShow5.Route = 0D; - DefetShow5.Scale = 1D; - DefetShow5.Size = new Size(209, 196); - DefetShow5.TabIndex = 10; - DefetShow5.WholeScale = 0F; - DefetShow5.XMove = 0F; - DefetShow5.XScale = 0F; - DefetShow5.YMove = 0F; - DefetShow5.YScale = 0F; + DefetShow7.AllowSelectDefect = true; + DefetShow7.BrushColor = null; + DefetShow7.ImagePath = ""; + mat3.IsEnabledDispose = true; + DefetShow7.ImaMAt = mat3; + DefetShow7.ImgData = null; + DefetShow7.Location = new Point(1021, 464); + DefetShow7.MoveStep = 5F; + DefetShow7.Name = "DefetShow7"; + DefetShow7.Route = 0D; + DefetShow7.Scale = 1D; + DefetShow7.Size = new Size(209, 196); + DefetShow7.TabIndex = 12; + DefetShow7.WholeScale = 0F; + DefetShow7.XMove = 0F; + DefetShow7.XScale = 0F; + DefetShow7.YMove = 0F; + DefetShow7.YScale = 0F; + // + // DefetShow6 + // + DefetShow6.AllowSelectDefect = true; + DefetShow6.BrushColor = null; + DefetShow6.ImagePath = ""; + mat4.IsEnabledDispose = true; + DefetShow6.ImaMAt = mat4; + DefetShow6.ImgData = null; + DefetShow6.Location = new Point(751, 464); + DefetShow6.MoveStep = 5F; + DefetShow6.Name = "DefetShow6"; + DefetShow6.Route = 0D; + DefetShow6.Scale = 1D; + DefetShow6.Size = new Size(209, 196); + DefetShow6.TabIndex = 11; + DefetShow6.WholeScale = 0F; + DefetShow6.XMove = 0F; + DefetShow6.XScale = 0F; + DefetShow6.YMove = 0F; + DefetShow6.YScale = 0F; // // panel8 // @@ -1290,6 +1335,27 @@ InitMachine.UseVisualStyleBackColor = true; InitMachine.Click += InitMachine_Click; // + // DefetShow2 + // + DefetShow2.AllowSelectDefect = true; + DefetShow2.BrushColor = null; + DefetShow2.ImagePath = ""; + mat5.IsEnabledDispose = true; + DefetShow2.ImaMAt = mat5; + DefetShow2.ImgData = null; + DefetShow2.Location = new Point(850, 249); + DefetShow2.MoveStep = 5F; + DefetShow2.Name = "DefetShow2"; + DefetShow2.Route = 0D; + DefetShow2.Scale = 1D; + DefetShow2.Size = new Size(285, 196); + DefetShow2.TabIndex = 9; + DefetShow2.WholeScale = 0F; + DefetShow2.XMove = 0F; + DefetShow2.XScale = 0F; + DefetShow2.YMove = 0F; + DefetShow2.YScale = 0F; + // // panel6 // panel6.Controls.Add(groupBox2); @@ -1318,6 +1384,27 @@ groupBox2.Text = "图片"; groupBox2.Enter += groupBox2_Enter; // + // DefetShow5 + // + DefetShow5.AllowSelectDefect = true; + DefetShow5.BrushColor = null; + DefetShow5.ImagePath = ""; + mat6.IsEnabledDispose = true; + DefetShow5.ImaMAt = mat6; + DefetShow5.ImgData = null; + DefetShow5.Location = new Point(537, 460); + DefetShow5.MoveStep = 5F; + DefetShow5.Name = "DefetShow5"; + DefetShow5.Route = 0D; + DefetShow5.Scale = 1D; + DefetShow5.Size = new Size(209, 196); + DefetShow5.TabIndex = 10; + DefetShow5.WholeScale = 0F; + DefetShow5.XMove = 0F; + DefetShow5.XScale = 0F; + DefetShow5.YMove = 0F; + DefetShow5.YScale = 0F; + // // DefetShow4 // DefetShow4.AllowSelectDefect = true; @@ -1360,27 +1447,6 @@ DefetShow3.YMove = 0F; DefetShow3.YScale = 0F; // - // DefetShow2 - // - DefetShow2.AllowSelectDefect = true; - DefetShow2.BrushColor = null; - DefetShow2.ImagePath = ""; - mat5.IsEnabledDispose = true; - DefetShow2.ImaMAt = mat5; - DefetShow2.ImgData = null; - DefetShow2.Location = new Point(850, 249); - DefetShow2.MoveStep = 5F; - DefetShow2.Name = "DefetShow2"; - DefetShow2.Route = 0D; - DefetShow2.Scale = 1D; - DefetShow2.Size = new Size(285, 196); - DefetShow2.TabIndex = 9; - DefetShow2.WholeScale = 0F; - DefetShow2.XMove = 0F; - DefetShow2.XScale = 0F; - DefetShow2.YMove = 0F; - DefetShow2.YScale = 0F; - // // originMat2Show // originMat2Show.Location = new Point(574, 21); @@ -1817,48 +1883,6 @@ contextMenuStrip1.Name = "contextMenuStrip1"; contextMenuStrip1.Size = new Size(61, 4); // - // DefetShow6 - // - DefetShow6.AllowSelectDefect = true; - DefetShow6.BrushColor = null; - DefetShow6.ImagePath = ""; - mat4.IsEnabledDispose = true; - DefetShow6.ImaMAt = mat4; - DefetShow6.ImgData = null; - DefetShow6.Location = new Point(751, 464); - DefetShow6.MoveStep = 5F; - DefetShow6.Name = "DefetShow6"; - DefetShow6.Route = 0D; - DefetShow6.Scale = 1D; - DefetShow6.Size = new Size(209, 196); - DefetShow6.TabIndex = 11; - DefetShow6.WholeScale = 0F; - DefetShow6.XMove = 0F; - DefetShow6.XScale = 0F; - DefetShow6.YMove = 0F; - DefetShow6.YScale = 0F; - // - // DefetShow7 - // - DefetShow7.AllowSelectDefect = true; - DefetShow7.BrushColor = null; - DefetShow7.ImagePath = ""; - mat3.IsEnabledDispose = true; - DefetShow7.ImaMAt = mat3; - DefetShow7.ImgData = null; - DefetShow7.Location = new Point(1021, 464); - DefetShow7.MoveStep = 5F; - DefetShow7.Name = "DefetShow7"; - DefetShow7.Route = 0D; - DefetShow7.Scale = 1D; - DefetShow7.Size = new Size(209, 196); - DefetShow7.TabIndex = 12; - DefetShow7.WholeScale = 0F; - DefetShow7.XMove = 0F; - DefetShow7.XScale = 0F; - DefetShow7.YMove = 0F; - DefetShow7.YScale = 0F; - // // MainForm // AutoScaleDimensions = new SizeF(7F, 17F); @@ -2056,7 +2080,7 @@ private Button openModelBtn; private TextBox modelChangeCbx; private Label label34; - private Button button1; + private Button HandRuningBtn; private Label label33; private CheckBox WhiteBanCbx; private XKRS.UI.Canvas DefetShow1; @@ -2069,5 +2093,6 @@ private PictureBox originMat2Show; private XKRS.UI.Canvas DefetShow7; private XKRS.UI.Canvas DefetShow6; + private Button handStopBtn; } } diff --git a/HisenceYoloDetection/MainForm.cs b/HisenceYoloDetection/MainForm.cs index 4e41ada..bd6ea61 100644 --- a/HisenceYoloDetection/MainForm.cs +++ b/HisenceYoloDetection/MainForm.cs @@ -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; @@ -24,6 +25,7 @@ using System.Text.RegularExpressions; 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; @@ -190,10 +192,11 @@ namespace HisenceYoloDetection private void MainForm_Load(object sender, EventArgs e) { - string s1 = "0##Ec04060##20##Rapide15mns"; - string s2 = "ECOmns"; + 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"; @@ -594,10 +597,10 @@ namespace HisenceYoloDetection melsecPLCTCPDriver.WriteInt("514", 0);//λɿ melsecPLCTCPDriver.WriteInt("524", 0);//λɿ melsecPLCTCPDriver.WriteInt("406", 60000); //дֶٶ - melsecPLCTCPDriver.WriteInt("416", 8000); + melsecPLCTCPDriver.WriteInt("416", 10000); melsecPLCTCPDriver.WriteInt("426", 10000); melsecPLCTCPDriver.WriteInt("404", 100000); //д붨λٶ - melsecPLCTCPDriver.WriteInt("414", 8000); + melsecPLCTCPDriver.WriteInt("414", 10000); melsecPLCTCPDriver.WriteInt("424", 10000); @@ -612,6 +615,7 @@ namespace HisenceYoloDetection Thread.Sleep(200); melsecPLCTCPDriver.WriteInt("580", 0); Thread.Sleep(200); + melsecPLCTCPDriver.WriteInt("550", 0); while (true) { int IfXZeros = melsecPLCTCPDriver.ReadInt("102"); @@ -1039,6 +1043,7 @@ namespace HisenceYoloDetection #endregion int YPos = 8715; int ZPos = 25000; + bool StopM = false;//һźŵ /// /// ϴ»544Ƿ񴥷䴫 /// @@ -1081,13 +1086,21 @@ namespace HisenceYoloDetection else { iNum1 = 0; + melsecPLCTCPDriver.WriteInt("550", 1);// } if (iNum1 >= 2) { //if (bBarTriger) { - + #if true + if(!StopM) + { + melsecPLCTCPDriver.WriteInt("550", 1);// + StopM = true; + + } + myLog("һβɼͼ", DateTime.Now); //ƶģ βĵַ Ƿǰƶ MoveToP(5815, YPos, ZPos); @@ -1116,7 +1129,7 @@ namespace HisenceYoloDetection // Thread.Sleep(500); Cam1.SnapshotCount = 0; Cam1.Snapshot(); - + Cam2.SnapshotCount = 0; Cam2.Snapshot(); myLog("ڶβɼͼ", DateTime.Now); @@ -1129,6 +1142,9 @@ namespace HisenceYoloDetection MoveToP(51043, YPos, ZPos + (int)(dismove)); Cam1.Snapshot(); MoveToP(5815, YPos, ZPos); + melsecPLCTCPDriver.WriteInt("550", 0);// + //Thread.Sleep(300);//ϴ»ܹȥ + //if (xKNow != null) //{ // MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ); @@ -1260,7 +1276,7 @@ namespace HisenceYoloDetection //Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\\\1\\001.jpg"); ; - Cam1ImgOne = cameraMat; + Cam1ImgOne = cameraMat; IfCam1OneTriger = true; originMatShow.Image = cameraMat.ToBitmap(); //pictureBox1.Image = cameraMat.ToBitmap(); @@ -1270,8 +1286,8 @@ namespace HisenceYoloDetection //ڶ if (SnapshotCount == 2) { - // Mat mat = Cv2.ImRead("D:\\Hisence\\\\1\\002.jpg"); - // Cam1ImgTwo = mat; + // Mat mat = Cv2.ImRead("D:\\Hisence\\\\1\\002.jpg"); + // Cam1ImgTwo = mat; Cam1ImgTwo = cameraMat; IfCam1TwoTriger = true; @@ -1342,7 +1358,7 @@ namespace HisenceYoloDetection sw.WriteLine(IOcrBAr + "\n"); sw.Flush(); } - IOcrBAr = "W821PWMS27106WD2"; + IOcrBAr = "BatchW96DHModelWF3S7021BWPl"; //ݿȶ xKNow = GetModeFromBar(IOcrBAr);//ݿвѯֵ List xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr); @@ -1503,7 +1519,7 @@ namespace HisenceYoloDetection bBarTriger = false; - + melsecPLCTCPDriver.WriteInt("550", 0);// if (MatchStr) { OKDsums++; @@ -1795,6 +1811,24 @@ 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(); TriggerCameral2(); ReadyDetect(); @@ -2629,7 +2663,7 @@ namespace HisenceYoloDetection break; case 7: { - DefetShow7.ImaMAt = detectionImage; + DefetShow7.ImaMAt = detectionImage; } break; case 8: @@ -2865,12 +2899,15 @@ 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) { - bool ssD= ManagerModelHelper.StrMatch(xK_HisenceWord.OneblockMainWord, SQLStr); - bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr); - if (!OneIF1||!ssD) + bool ssD = ManagerModelHelper.StrMatch(SQLStr, xK_HisenceWord.OneblockText); + Console.Write(SQLStr); + bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr2); + if (!OneIF1 || !ssD) { OneIF = false; //ʾİ @@ -2930,16 +2967,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;//޸6.28 + /* DisplayResult(mLcut); //ʾİ // mLcut.ResultMap; Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 3); + */ + Defet_OnDetectionDone(OKMat, 3); } else { + OneIF = true; Defet_OnDetectionDone(OKMat, 3); } @@ -2954,9 +3001,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); //ʾİ // mLcut.ResultMap; @@ -2964,6 +3017,7 @@ namespace HisenceYoloDetection } else { + OneIF = true; Defet_OnDetectionDone(OKMat, 4); } @@ -2978,9 +3032,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); //ʾİ // mLcut.ResultMap; @@ -2988,6 +3047,7 @@ namespace HisenceYoloDetection } else { + OneIF = true; Defet_OnDetectionDone(OKMat, 5); } } @@ -3001,18 +3061,26 @@ namespace HisenceYoloDetection if (!saveimage) { SQLStr = SQlxK_HisenceWord.SixblockMainWord; - OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord); - if (!OneIF) - { - // DisplayResult(mLcut); - //ʾİ - // mLcut.ResultMap; - Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 6); - } - else - { - Defet_OnDetectionDone(OKMat, 6); - } + bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord); + + Rect rect = new Rect(0, 0, 0, 0); + string PathSql = SQlxK_HisenceWord.SixblockPath; + + juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test"); + if (!OneIF1 || !juanjiMatch) + if (!OneIF) + { + OneIF = false; + // DisplayResult(mLcut); + //ʾİ + // mLcut.ResultMap; + Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 6); + } + else + { + OneIF = true; + Defet_OnDetectionDone(OKMat, 6); + } } } @@ -3025,9 +3093,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); //ʾİ // mLcut.ResultMap; @@ -3035,6 +3108,7 @@ namespace HisenceYoloDetection } else { + OneIF = true; Defet_OnDetectionDone(OKMat, 7); } } @@ -3048,9 +3122,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); //ʾİ // mLcut.ResultMap; @@ -3058,6 +3137,7 @@ namespace HisenceYoloDetection } else { + OneIF = true; Defet_OnDetectionDone(OKMat, 8); } } @@ -3070,10 +3150,7 @@ namespace HisenceYoloDetection using (StreamWriter sw = new StreamWriter(txtLog, true)) { - if (blockIndex == "2") - { - sw.WriteLine("ƥ" + juanjiMatch); - } + sw.WriteLine("" + blockIndex + "ƥ" + juanjiMatch); sw.WriteLine("" + blockIndex + "ݿ" + SQLStr + "ؼ" + MainWoidStr + "" + OneIF + "\n"); sw.WriteLine("" + blockIndex + " " + TextWoidStr + "\n"); @@ -3125,5 +3202,15 @@ namespace HisenceYoloDetection myLog("Xֹͣ", 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); + } } } diff --git a/HisenceYoloDetection/ManagerModelHelper.cs b/HisenceYoloDetection/ManagerModelHelper.cs index d77cd96..1af0ee4 100644 --- a/HisenceYoloDetection/ManagerModelHelper.cs +++ b/HisenceYoloDetection/ManagerModelHelper.cs @@ -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; }