Compare commits

...

9 Commits

9 changed files with 1276 additions and 815 deletions

View File

@ -1,10 +1,12 @@
using OpenCvSharp; using OpenCvSharp;
using Sunny.UI.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using Point = OpenCvSharp.Point; using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size; using Size = OpenCvSharp.Size;
@ -12,9 +14,8 @@ using Size = OpenCvSharp.Size;
namespace HisenceYoloDetection namespace HisenceYoloDetection
{ {
public static class CheckDiffSciHelper public static class CheckDiffSciHelper
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -22,40 +23,40 @@ namespace HisenceYoloDetection
/// <param name="path2">要对比的图像</param> /// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param> /// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</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); Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
if (img1.Empty()) if (img1.Empty())
{ {
Console.WriteLine($"Error loading image {path1}"); Console.WriteLine($"Error loading image {path1}");
return false; return false;
} }
// Cv2.Resize(img1, img1, new Size(550, 270)); // Cv2.Resize(img1, img1, new Size(550, 270));
Mat gimg1 = new Mat(); Mat gimg1 = new Mat();
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY); Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
Mat thr1 = new Mat(); Mat thr1 = new Mat();
if(IfWhiteWord) if (IfWhiteWord)
{ {
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu); Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
} }
else else
{ {
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu); Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
} }
// 读取和处理第二张图片 // 读取和处理第二张图片
Mat img2 = MatDet.Clone(); Mat img2 = MatDet.Clone();
if (img2.Empty()) if (img2.Empty())
{ {
// Console.WriteLine($"Error loading image {path2}"); // Console.WriteLine($"Error loading image {path2}");
return false; return false;
} }
// Cv2.Resize(img2, img2, new Size(550, 270)); // Cv2.Resize(img2, img2, new Size(550, 270));
Mat gimg2 = new Mat(); Mat gimg2 = new Mat();
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY); Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
Mat thr2 = new Mat(); Mat thr2 = new Mat();
@ -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);
} }
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
//Rect area2 = new Rect(148,30,229,222); //Rect area2 = new Rect(148,30,229,222);
sqlrect.Width += 20; sqlrect.Width += 20;
sqlrect.Height += 60;
detrect.Width += 20; detrect.Width += 20;
detrect.Height += 60;
Mat matCutblack1 = new Mat(thr1, sqlrect); Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord) if (IfWhiteWord)
{ {
@ -95,17 +96,17 @@ namespace HisenceYoloDetection
} }
Cv2.Resize(thr1, thr1, new Size(550, 270)); Cv2.Resize(thr1, thr1, new Size(550, 270));
Cv2.Resize(thr2, thr2, new Size(550, 270)); Cv2.Resize(thr2, thr2, new Size(550, 270));
DateTime dt= DateTime.Now; 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 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); //Cv2.ImWrite(savePath4, thr1);
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png"); //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)); Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
@ -145,10 +146,17 @@ namespace HisenceYoloDetection
Mat devIMG_ = new Mat(); Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG); Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, 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, 20, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary); Cv2.Threshold(devIMG_, devIMG_, 20, 255, ThresholdTypes.Binary);
// 结合差异 // 结合差异
Mat sumIMG = new Mat(); Mat sumIMG = new Mat();
@ -160,36 +168,46 @@ namespace HisenceYoloDetection
Cv2.Dilate(sumIMG, blackhatImg, kernelCL); Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
// 处理轮廓和保存结果 // 处理轮廓和保存结果
Point[][] contours = new Point[10000][]; Point[][] contours = new Point[10000][];
Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple); Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
bool isMatch = true; bool isMatch = true;
foreach (var contour in contours) 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); 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 else
{ {
Rect boundingRect = Cv2.BoundingRect(contour); Rect boundingRect = Cv2.BoundingRect(contour);
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2); Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
isMatch= false; 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);
} }
} }
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; return isMatch;
} }
public static Rect strChangeRect(string strrect) public static Rect strChangeRect(string strrect)
{ {
if (!string.IsNullOrEmpty(strrect)) if (!string.IsNullOrEmpty(strrect))
@ -202,14 +220,15 @@ namespace HisenceYoloDetection
Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight); Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight);
return rect; 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]; string[] rectsql = new string[4];
rectsql[0] = Convert.ToString(area.X); rectsql[0] = Convert.ToString(area.X);
@ -220,123 +239,198 @@ namespace HisenceYoloDetection
string strrect = rectsql.Join(","); string strrect = rectsql.Join(",");
return strrect; return strrect;
} }
//public static void CheckDiffSci(string path1, string path2, bool IfWhiteWord, string saveDir) public static class CheckDiffSciHelper1
//{ {
// // 读取和处理第一张图片 /// <summary>
// Mat img1 = Cv2.ImRead(path1, ImreadModes.Color); ///
// if (img1.Empty()) /// </summary>
// { /// <param name="path1">标准图像</param>
// Console.WriteLine($"Error loading image {path1}"); /// <param name="path2">要对比的图像</param>
// return; /// <param name="IfWhiteWord"> 白板黑字为true </param>
// } /// <param name="saveDir">存储路径</param>
// Cv2.Resize(img1, img1, new Size(550, 270)); public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
// Mat gimg1 = new Mat(); {
// Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY); // 读取和处理第一张图片
// Mat thr1 = new Mat(); 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) if (IfWhiteWord)
// { {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu); Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// } }
// else else
// { {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu); 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"); // 读取和处理第二张图片
// // 保存结果 Mat img2 = MatDet.Clone();
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); if (img2.Empty())
// Cv2.ImWrite(savePath3, thr2); {
// 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));
// // 应用卷积 //Rect area2 = new Rect(148,30,229,222);
// Mat final_result1 = new Mat(); sqlrect.Width += 20;
// Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); sqlrect.Height += 20;
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); detrect.Width += 20;
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); 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(); //string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
// 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.ImWrite(savePath4, thr1);
// Mat devIMG = new Mat(); //string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
// Mat devIMG_ = new Mat(); //// 保存结果
// Cv2.Subtract(final_result1, final_result2, devIMG);
// Cv2.Subtract(final_result2, final_result1, devIMG_);
// // 对差异图像应用阈值 //Cv2.ImWrite(savePath3, thr2);
// 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 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(); Mat final_result1 = new Mat();
// Cv2.Dilate(sumIMG, blackhatImg, kernelCL); 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();
// Point[][] contours = new Point[10000][]; Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
// Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple); 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);
// // 框选轮廓
// } //string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result1.png");
// else //// 保存结果
// { ////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Rect boundingRect = Cv2.BoundingRect(contour); //Cv2.ImWrite(savePath2, final_result1);
// Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2); //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result2.png");
// } //// 保存结果
// } ////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_Rect.png"); //Cv2.ImWrite(savePath, final_result2);
// // 保存结果
// //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);
//} // 计算图像差异
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;
}
}
} }
} }

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,8 @@ using OpenCvSharp;
using OpenCvSharp.Dnn; using OpenCvSharp.Dnn;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
using OpenCvSharp.XFeatures2D; using OpenCvSharp.XFeatures2D;
using Sunny.UI;
using Sunny.UI.Win32;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -20,9 +22,11 @@ using System.Net;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using XKRS.Device.SimboVision.SimboHelper; using XKRS.Device.SimboVision.SimboHelper;
using XKRS.UI; using XKRS.UI;
using static HisenceYoloDetection.CheckDiffSciHelper;
using static HisenceYoloDetection.MainForm; using static HisenceYoloDetection.MainForm;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
using static System.Windows.Forms.VisualStyles.VisualStyleElement; using static System.Windows.Forms.VisualStyles.VisualStyleElement;
@ -61,6 +65,9 @@ namespace HisenceYoloDetection
List<XKHisence> xKHisences = new List<XKHisence>(); List<XKHisence> xKHisences = new List<XKHisence>();
static AutoResetEvent myResetEvent = new AutoResetEvent(false); static AutoResetEvent myResetEvent = new AutoResetEvent(false);
AutoResetEvent _runHandleBefore = new AutoResetEvent(false);
ManualResetEvent _runHandleAfter = new ManualResetEvent(false);
bool PLC545 = false; bool PLC545 = false;
bool PLC548 = false; bool PLC548 = false;
@ -100,7 +107,11 @@ namespace HisenceYoloDetection
string Cam1OnePath = ""; string Cam1OnePath = "";
string Cam1TwoPath = ""; string Cam1TwoPath = "";
string ModelChangePath = ""; string ModelChangePath = "";
//报警灯
string GreenLightingAdress = "";
string YellowLightingAdress = "";
string RedLightingAdress = "";
string WaringAdress = "";
/// <summary> /// <summary>
/// 查看相机列表 /// 查看相机列表
/// </summary> /// </summary>
@ -188,11 +199,25 @@ namespace HisenceYoloDetection
/// <param name="e"></param> /// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e) private void MainForm_Load(object sender, EventArgs e)
{ {
//报警地址
string s1 = "ECO4060##Coton20℃##Rapide15mns"; if (_runHandleBefore == null)
string s2 = "Eco4060##Coton20℃##Rapide15mns"; {
_runHandleBefore = new AutoResetEvent(false);
}
bool st = ManagerModelHelper.StrMatch2(s1, s2); 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); //Rect rect = new Rect(0, 0, 0, 0);
//string path2 = "D:\\Hisence\\SQLImages\\W80WXWJ060539V0WW80WX120293\\2\\W80WXWJ060539V0WW80WX120293result.jpg"; //string path2 = "D:\\Hisence\\SQLImages\\W80WXWJ060539V0WW80WX120293\\2\\W80WXWJ060539V0WW80WX120293result.jpg";
@ -264,6 +289,8 @@ namespace HisenceYoloDetection
OnSpeedShow();//线程开启将速度显示在界面上 OnSpeedShow();//线程开启将速度显示在界面上
OnPostionShow();//线程开启将位置显示在界面上 OnPostionShow();//线程开启将位置显示在界面上
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
//t = new System.Timers.Timer(10000);//实例化Timer类设置间隔时间为10000毫秒 //t = new System.Timers.Timer(10000);//实例化Timer类设置间隔时间为10000毫秒
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件; //t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件;
//t.AutoReset = true;//设置是执行一次false还是一直执行(true) //t.AutoReset = true;//设置是执行一次false还是一直执行(true)
@ -273,6 +300,7 @@ namespace HisenceYoloDetection
} }
public void Execute(object source, System.Timers.ElapsedEventArgs e) public void Execute(object source, System.Timers.ElapsedEventArgs e)
{ {
t.Stop(); //先关闭定时器 t.Stop(); //先关闭定时器
//melsecPLCTCPDriver.WriteInt("548", 1); //melsecPLCTCPDriver.WriteInt("548", 1);
//Thread.Sleep(1000); //Thread.Sleep(1000);
@ -520,6 +548,7 @@ namespace HisenceYoloDetection
// tbFrameRate.Enabled = false; // tbFrameRate.Enabled = false;
bnGetParam.Enabled = false; bnGetParam.Enabled = false;
bnSetParam.Enabled = false; bnSetParam.Enabled = false;
} }
private void button3_Click(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e)
{ {
@ -549,6 +578,7 @@ namespace HisenceYoloDetection
Bitmap NGbitmap = new Bitmap("NG.jpg"); Bitmap NGbitmap = new Bitmap("NG.jpg");
Mat OKMat = Cv2.ImRead("OK.jpg"); Mat OKMat = Cv2.ImRead("OK.jpg");
Mat NGMat = Cv2.ImRead("OK.jpg"); Mat NGMat = Cv2.ImRead("OK.jpg");
Mat whiteMat = Cv2.ImRead("white.jpg");
/// <summary> /// <summary>
/// 主线程调用 /// 主线程调用
/// </summary> /// </summary>
@ -585,17 +615,17 @@ namespace HisenceYoloDetection
//Scanner.OnClientDataReceived += OnDataReceived; //Scanner.OnClientDataReceived += OnDataReceived;
//Scanner.btnSendMsg("LON\r");//发送开启指令 //Scanner.btnSendMsg("LON\r");//发送开启指令
//myLog("发送恩士扫码枪开启指令", DateTime.Now); //myLog("发送恩士扫码枪开启指令", DateTime.Now);
//PLC使能开启 //PLC使能开启
melsecPLCTCPDriver.WriteInt("581", 0);//定位松开 melsecPLCTCPDriver.WriteInt("581", 0);//定位松开
melsecPLCTCPDriver.WriteInt("504", 0);//定位松开 melsecPLCTCPDriver.WriteInt("504", 0);//定位松开
melsecPLCTCPDriver.WriteInt("514", 0);//定位松开 melsecPLCTCPDriver.WriteInt("514", 0);//定位松开
melsecPLCTCPDriver.WriteInt("524", 0);//定位松开 melsecPLCTCPDriver.WriteInt("524", 0);//定位松开
melsecPLCTCPDriver.WriteInt("406", 60000); //写入手动速度 melsecPLCTCPDriver.WriteInt("406", 60000); //写入手动速度
melsecPLCTCPDriver.WriteInt("416", 8000); melsecPLCTCPDriver.WriteInt("416", 10000);
melsecPLCTCPDriver.WriteInt("426", 10000); melsecPLCTCPDriver.WriteInt("426", 10000);
melsecPLCTCPDriver.WriteInt("404", 100000); //写入定位速度 melsecPLCTCPDriver.WriteInt("404", 100000); //写入定位速度
melsecPLCTCPDriver.WriteInt("414", 8000); melsecPLCTCPDriver.WriteInt("414", 10000);
melsecPLCTCPDriver.WriteInt("424", 10000); melsecPLCTCPDriver.WriteInt("424", 10000);
@ -610,6 +640,7 @@ namespace HisenceYoloDetection
Thread.Sleep(200); Thread.Sleep(200);
melsecPLCTCPDriver.WriteInt("580", 0); melsecPLCTCPDriver.WriteInt("580", 0);
Thread.Sleep(200); Thread.Sleep(200);
melsecPLCTCPDriver.WriteInt("550", 0);
while (true) while (true)
{ {
int IfXZeros = melsecPLCTCPDriver.ReadInt("102"); int IfXZeros = melsecPLCTCPDriver.ReadInt("102");
@ -975,11 +1006,12 @@ namespace HisenceYoloDetection
} }
if (iNum1 >= 2) if (iNum1 >= 2)
{ {
if (bBar) if (bBar)
{ {
_runHandleBefore.WaitOne();
bBarTriger = true;//修改成相机拍照获取型号 bBarTriger = true;//修改成相机拍照获取型号
Cam2.SnapshotCount = 0;
Cam2.Snapshot();
xKNow = GetModeFromBar("VWJ070633V0WW80F0120356");//从数据库中查询到这个条码的四轴的值 xKNow = GetModeFromBar("VWJ070633V0WW80F0120356");//从数据库中查询到这个条码的四轴的值
//xKNow = GetModeFromBar(m_sKEYENCEBar);//从数据库中查询到这个条码的四轴的值 //xKNow = GetModeFromBar(m_sKEYENCEBar);//从数据库中查询到这个条码的四轴的值
@ -1037,6 +1069,7 @@ namespace HisenceYoloDetection
#endregion #endregion
int YPos = 8715; int YPos = 8715;
int ZPos = 25000; int ZPos = 25000;
bool StopM = false;//第一次用信号挡
/// <summary> /// <summary>
/// 监听洗衣机544是否触发后面对射传感器 相机 /// 监听洗衣机544是否触发后面对射传感器 相机
/// </summary> /// </summary>
@ -1079,13 +1112,21 @@ namespace HisenceYoloDetection
else else
{ {
iNum1 = 0; iNum1 = 0;
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
} }
if (iNum1 >= 2) if (iNum1 >= 2)
{ {
//if (bBarTriger) //if (bBarTriger)
{ {
#if true #if false
if (!StopM)
{
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
StopM = true;
}
myLog("第一次采集图像", DateTime.Now); myLog("第一次采集图像", DateTime.Now);
//移动模组 读三次测距的地址 看是否往前移动 //移动模组 读三次测距的地址 看是否往前移动
MoveToP(5815, YPos, ZPos); MoveToP(5815, YPos, ZPos);
@ -1106,7 +1147,7 @@ namespace HisenceYoloDetection
double disreal = average * (-0.54054) + 1324.3232; double disreal = average * (-0.54054) + 1324.3232;
//测距距离-标准距离=要移动的距离 //测距距离-标准距离=要移动的距离
double dismove = disreal - 876; double dismove = disreal - 876;
if (dismove > 0 && dismove < 4000) if (dismove > -4000 && dismove < 4000)
{ {
MoveToP(5815, YPos, ZPos + (int)(dismove)); MoveToP(5815, YPos, ZPos + (int)(dismove));
} }
@ -1114,19 +1155,22 @@ namespace HisenceYoloDetection
// Thread.Sleep(500); // Thread.Sleep(500);
Cam1.SnapshotCount = 0; Cam1.SnapshotCount = 0;
Cam1.Snapshot(); Cam1.Snapshot();
Cam2.SnapshotCount = 0; Cam2.SnapshotCount = 0;
Cam2.Snapshot(); Cam2.Snapshot();
myLog("第二次采集图像", DateTime.Now); myLog("第二次采集图像", DateTime.Now);
//if (xKNow != null) //if (xKNow != null)
//{ //{
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ); // MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
//} //}
//currentXP = 54964;
//Thread.Sleep(2000);//删
MoveToP(51043, YPos, ZPos + (int)(dismove)); MoveToP(51043, YPos, ZPos + (int)(dismove));
Cam1.Snapshot(); Cam1.Snapshot();
MoveToP(5815, YPos, ZPos); MoveToP(5815, YPos, ZPos);
melsecPLCTCPDriver.WriteInt("550", 0);//方行
//Thread.Sleep(300);//洗衣机可能过不去
//if (xKNow != null) //if (xKNow != null)
//{ //{
// MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ); // MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);
@ -1168,7 +1212,7 @@ namespace HisenceYoloDetection
// Thread.Sleep(500); // Thread.Sleep(500);
Cam1.SnapshotCount = 0; Cam1.SnapshotCount = 0;
Cam1.Snapshot(); Cam1.Snapshot();
// Cam2.SnapshotCount = 0; // Cam2.SnapshotCount = 0;
//Cam2.Snapshot(); //Cam2.Snapshot();
IfCam2Triger = true; IfCam2Triger = true;
@ -1179,7 +1223,7 @@ namespace HisenceYoloDetection
//} //}
//currentXP = 54964; //currentXP = 54964;
Thread.Sleep(2000);//删 Thread.Sleep(2000);//删
//MoveToP(51043, YPos, ZPos + (int)(dismove)); //MoveToP(51043, YPos, ZPos + (int)(dismove));
Cam1.Snapshot(); Cam1.Snapshot();
//MoveToP(5815, YPos, ZPos); //MoveToP(5815, YPos, ZPos);
@ -1257,8 +1301,8 @@ namespace HisenceYoloDetection
{ {
// Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\类型\\1\\202461817464661.jpg"); ; Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\类型\\1\\001.jpg"); ;
Cam1ImgOne = cameraMat; //Cam1ImgOne = cameraMat;
IfCam1OneTriger = true; IfCam1OneTriger = true;
originMatShow.Image = cameraMat.ToBitmap(); originMatShow.Image = cameraMat.ToBitmap();
//pictureBox1.Image = cameraMat.ToBitmap(); //pictureBox1.Image = cameraMat.ToBitmap();
@ -1268,13 +1312,13 @@ namespace HisenceYoloDetection
//第二次拍照 //第二次拍照
if (SnapshotCount == 2) if (SnapshotCount == 2)
{ {
//Mat mat = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
//Cam1ImgTwo = mat; Cam1ImgTwo = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
Cam1ImgTwo = cameraMat; //Cam1ImgTwo = cameraMat;
IfCam1TwoTriger = true; IfCam1TwoTriger = true;
originMatShow2.Image = cameraMat.ToBitmap(); originMatShow2.Image = cameraMat.ToBitmap();
_runHandleAfter.Set();
} }
@ -1300,8 +1344,9 @@ namespace HisenceYoloDetection
// Mat mat = Cv2.ImRead("F:\\海信洗衣机\\cam1\\2024517161641.jpg"); // Mat mat = Cv2.ImRead("F:\\海信洗衣机\\cam1\\2024517161641.jpg");
Cam2ImgShowBar = cameraMat; Cam2ImgShowBar = cameraMat;
IfCam2Triger = true; IfCam2Triger = true;
originMat2Show.Image = cameraMat.ToBitmap();
originMat2Show.Image = cameraMat.ToBitmap();
//_runHandleAfter.Set();
// CamShow2.ImaMAt = cameraMat; // 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"); cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
@ -1309,18 +1354,21 @@ namespace HisenceYoloDetection
public volatile int AllDsums = 0; public volatile int AllDsums = 0;
public volatile int NGDsums = 0; public volatile int NGDsums = 0;
public volatile int OKDsums = 0; public volatile int OKDsums = 0;
public volatile int WUsums = 0;
/// <summary> /// <summary>
/// 开始识别 /// 开始识别
/// </summary> /// </summary>
public void ReadyDetect() public void ReadyDetect()
{ {
Task.Run((Action)(() => _ = Task.Run((Action)(() =>
{ {
Thread.CurrentThread.Priority = ThreadPriority.Highest; Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (true) while (true)
{ {
try try
{ {
//信号量阻塞 使其不在总数增加和闪烁
_runHandleAfter.WaitOne();
//相机2第一次拍照 //相机2第一次拍照
if (IfCam2Triger) if (IfCam2Triger)
{ {
@ -1340,7 +1388,8 @@ namespace HisenceYoloDetection
sw.WriteLine(IOcrBAr + "\n"); sw.WriteLine(IOcrBAr + "\n");
sw.Flush(); sw.Flush();
} }
IOcrBAr = "BatchW825UModelWNHEI74SAS"; // IOcrBAr = "BatchW9659ModelWNHPI74SCPSDE";
IOcrBAr = "W821PWMS27106WD2";
//根据条码数据库比对 //根据条码数据库比对
xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值 xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr); List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
@ -1381,12 +1430,24 @@ namespace HisenceYoloDetection
//从数据库中匹配完才可以进行模组移动 //从数据库中匹配完才可以进行模组移动
//如果这次型号和上次的型号一样 就不用换识别模型ll //如果这次型号和上次的型号一样 就不用换识别模型ll
} }
//相机1第二次拍照 //相机1第二次拍照
if (IfCam1TwoTriger && bBarTriger) // if (IfCam1TwoTriger && bBarTriger)
{ {
IfCam1TwoTriger = false;
bBarTriger = false;
_runHandleAfter.Reset();
//初始化板
Defet_OnDetectionDone(whiteMat, 1);
Defet_OnDetectionDone(whiteMat, 2);
Defet_OnDetectionDone(whiteMat, 3);
Defet_OnDetectionDone(whiteMat, 4);
Defet_OnDetectionDone(whiteMat, 5);
Defet_OnDetectionDone(whiteMat, 6);
Defet_OnDetectionDone(whiteMat, 7);
XK_HisenceWord xK_MatchDet = new XK_HisenceWord(); XK_HisenceWord xK_MatchDet = new XK_HisenceWord();
xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile; xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
AllDsums++; AllDsums++;
@ -1408,19 +1469,14 @@ namespace HisenceYoloDetection
List<string> strMatListOne = new List<string>(); List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>(); List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = req.currentMat.Clone(); 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("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
if (mL.ResultMap != null) 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"); 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; ResultMatShow.Image = mL.ResultMap;
} }
//进行推理 //进行推理
MLRequest req2 = new MLRequest(); MLRequest req2 = new MLRequest();
req2.currentMat = Cam1ImgTwo; req2.currentMat = Cam1ImgTwo;
@ -1432,18 +1488,18 @@ namespace HisenceYoloDetection
req2.iouThreshold = 0.4f;//检测IOU req2.iouThreshold = 0.4f;//检测IOU
req2.out_node_name = "output"; req2.out_node_name = "output";
MLResult mL2 = simboObjectDetection.RunInferenceFixed(req2); 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) 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"); 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; 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
//执行定位数组块 //执行定位数组块
string[] listLabels = xKNow.Detect.Split(","); string[] listLabels = xKNow.Detect.Split(",");
@ -1466,34 +1522,49 @@ namespace HisenceYoloDetection
detstr += RealLabels[i]; detstr += RealLabels[i];
} }
}
//排序比对块
HashSet<string> set1 = new HashSet<string>(listLabels);
HashSet<string> set2 = new HashSet<string>(RealLabels);
bool MatchStr = set1.SetEquals(set2);
#endregion
//块比对完了 进行详细比对
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("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
}
if (MatchStr)
{
//判断块值是否有含有匹配false
bool containsFalseValue = keyValueResult.ContainsValue(false);
bool containsFalseValue2 = keyValueResult2.ContainsValue(false);
if (containsFalseValue || containsFalseValue2)
MatchStr = false;
} }
///执行比对 小图 ///执行比对 小图
//bool MatchStr = ManagerModelHelper.IsMatchSQLText(ref mCut, ref xK_HisenceSQLWord, ref xK_MatchDet); //bool MatchStr = ManagerModelHelper.IsMatchSQLText(ref mCut, ref xK_HisenceSQLWord, ref xK_MatchDet);
bool MatchStr = true;
keyValueResult.ForEach(x =>
{
if (x.Value == false)
{
MatchStr = false;
return;
}
});
keyValueResult2.ForEach(x =>
{
if (x.Value == false)
{
MatchStr = false;
return;
}
});
IfCam1TwoTriger = false;
bBarTriger = false;
// int sqlblocksum=
melsecPLCTCPDriver.WriteInt("550", 0);//方行
if (MatchStr) if (MatchStr)
{ {
OKDsums++; OKDsums++;
@ -1509,14 +1580,39 @@ namespace HisenceYoloDetection
} }
else else
{ {
NGDsums++; melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
myLog("匹配失败", DateTime.Now); myLog("匹配失败", DateTime.Now);
//界面显示 //加上人为判断是否是NG洗衣机
// InsertXK_HisenceWordMatchData(xK_MatchDet, false); DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
this.Invoke(new Action(() => if (dr == DialogResult.OK)
{ {
OKOrNGShow.Image = NGbitmap; melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
})); melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
OKDsums++;
WUsums++;
this.Invoke(new Action(() =>
{
double percent = (double)WUsums/ AllDsums;
string percentText = percent.ToString("0.0%");//最后percentText的值为10.0%
textBox1.Text = percentText;
OKOrNGShow.Image = OKbitmap;
}));
}
else
{
NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
this.Invoke(new Action(() =>
{
OKOrNGShow.Image = NGbitmap;
}));
}
} }
@ -1525,7 +1621,7 @@ namespace HisenceYoloDetection
} }
catch (Exception e) catch (Exception e)
{ {
throw e;
} }
finally finally
{ {
@ -1605,7 +1701,7 @@ namespace HisenceYoloDetection
{ {
m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data); m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data);
// myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now); // myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now);
_runHandleBefore.Set();
bBar = true; bBar = true;
} }
@ -1785,17 +1881,31 @@ namespace HisenceYoloDetection
private void StartDecBtn_Click(object sender, EventArgs e) 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(); //OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯
TriggerCameral2(); TriggerCameral2();
ReadyDetect(); ReadyDetect();
myLog("开启流程成功", DateTime.Now); myLog("开启流程成功", DateTime.Now);
} }
private void InsertSqlBtn_Click(object sender, EventArgs e)
{
}
private void RefeshData_Click(object sender, EventArgs e) private void RefeshData_Click(object sender, EventArgs e)
{ {
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet"); DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
@ -1849,7 +1959,7 @@ namespace HisenceYoloDetection
} }
//按下状态标识 //按下状态标识
private bool m_btnState; private bool m_btnState;
private void YZerorbx_Click(object sender, EventArgs e) private void YZerorbx_Click(object sender, EventArgs e)
{ {
@ -2188,9 +2298,9 @@ namespace HisenceYoloDetection
List<string> strMatListOne = new List<string>(); List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>(); List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = CamOneI.currentMat.Clone(); Mat mResultCut = CamOneI.currentMat.Clone();
Mat mCut = new Mat(); //Mat mCut = new Mat();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>(); 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);
@ -2594,42 +2704,42 @@ namespace HisenceYoloDetection
{ {
case 1: case 1:
{ {
DefetShow1.ImaMAt = detectionImage; canvas1.ImaMAt = detectionImage;
} }
break; break;
case 2: case 2:
{ {
DefetShow2.ImaMAt = detectionImage; canvas2.ImaMAt = detectionImage;
} }
break; break;
case 3: case 3:
{ {
DefetShow3.ImaMAt = detectionImage; canvas3.ImaMAt = detectionImage;
} }
break; break;
case 4: case 4:
{ {
DefetShow4.ImaMAt = detectionImage; canvas4.ImaMAt = detectionImage;
} }
break; break;
case 5: case 5:
{ {
DefetShow5.ImaMAt = detectionImage; canvas5.ImaMAt = detectionImage;
} }
break; break;
case 6: case 6:
{ {
// DefetShow6.ImaMAt = detectionImage; canvas6.ImaMAt = detectionImage;
} }
break; break;
case 7: case 7:
{ {
// DefetShow7.ImaMAt = detectionImage; // canvas7.ImaMAt = detectionImage;
} }
break; break;
case 8: case 8:
{ {
// DefetShow8.ImaMAt = detectionImage; //DefetShow8.ImaMAt = detectionImage;
} }
break; break;
@ -2654,12 +2764,18 @@ namespace HisenceYoloDetection
/// <param name="strMatList">返回的定位框的结果</param> /// <param name="strMatList">返回的定位框的结果</param>
/// <param name="strMatRefList"></param> /// <param name="strMatRefList"></param>
/// <param name="IOcrModel"></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 #if true
//try //try
//{ //{
string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
string txtLog = "D://Hisence//" + filename + "logsMatch.log";
using (StreamWriter sw = new StreamWriter(txtLog, true))
{
sw.WriteLine(filename + "\n");
sw.Flush();
}
Mat mResultCut = currentMatC.Clone(); Mat mResultCut = currentMatC.Clone();
Rect areaBlack = new Rect(); Rect areaBlack = new Rect();
//旋钮的位置 //旋钮的位置
@ -2673,9 +2789,9 @@ namespace HisenceYoloDetection
areaBlack = new Rect(rectsx, rectsy, rectsWidth, rectsHeight); areaBlack = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
} }
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
{ {
Mat mResultCuti = mResultCut.Clone(); Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1TwoML.ResultDetails[i].Rect.X; int rectsx = cam1TwoML.ResultDetails[i].Rect.X;
@ -2684,16 +2800,16 @@ namespace HisenceYoloDetection
int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height; int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height;
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay; string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
if(keyValueResult.Keys.Contains(blockIndex)) if (keyValueResult.Keys.Contains(blockIndex))
{ {
int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex); int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex);
int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X; int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X;
if(rectsx> rectsxof) if (rectsx > rectsxof)
{ {
blockIndex = "3"; blockIndex = "3";
} }
} }
Rect area2 = new Rect(0, 0, 0, 0); Rect area2 = new Rect(0, 0, 0, 0);
Mat matCut = new Mat(); Mat matCut = new Mat();
@ -2766,6 +2882,7 @@ namespace HisenceYoloDetection
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay; string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight); Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCuti, area); Mat matCut = new Mat(mResultCuti, area);
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
//OCR识别裁剪图片 //OCR识别裁剪图片
@ -2847,6 +2964,7 @@ namespace HisenceYoloDetection
string TextWoidStr = OcrFuzzyTextInsert.Join("##"); //实际的检测字 string TextWoidStr = OcrFuzzyTextInsert.Join("##"); //实际的检测字
string SQLStr = "";//日志显示数据库的关键字 string SQLStr = "";//日志显示数据库的关键字
bool juanjiMatch = false; 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) switch (blockIndex)
{ {
case "1"://完全匹配 重量信息 case "1"://完全匹配 重量信息
@ -2854,19 +2972,31 @@ namespace HisenceYoloDetection
xK_HisenceWord.OneblockPath = CutSavePath; xK_HisenceWord.OneblockPath = CutSavePath;
xK_HisenceWord.OneblockMainWord = MainWoidStr; xK_HisenceWord.OneblockMainWord = MainWoidStr;
xK_HisenceWord.OneblockText = TextWoidStr; xK_HisenceWord.OneblockText = TextWoidStr;
SQLStr = SQlxK_HisenceWord.OneblockMainWord; SQLStr = SQlxK_HisenceWord.OneblockText;
string SQLStr2 = SQlxK_HisenceWord.OneblockMainWord;
if (!saveimage) if (!saveimage)
{ {
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr); bool ssD = ManagerModelHelper.StrMatch(SQLStr, xK_HisenceWord.OneblockText);
if (!OneIF) Console.Write(SQLStr);
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr2);
if (!OneIF1 || !ssD)
{ {
OneIF = false;
//显示错误的板 //显示错误的板
DisplayResult(mLcut); DisplayResult(mLcut);
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 1); 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 else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 1); Defet_OnDetectionDone(OKMat, 1);
string Path_2 = Path.Combine("D:\\Hisence\\Test\\1\\ok", filenameone + "_res.png");
Cv2.ImWrite(Path_2, OKMat);
} }
} }
@ -2881,7 +3011,7 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.TwoblockMainWord; SQLStr = SQlxK_HisenceWord.TwoblockMainWord;
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.TwoblockMainWord, SQlxK_HisenceWord.TwoblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.TwoblockMainWord, SQlxK_HisenceWord.TwoblockMainWord);
OneIF1 = true; OneIF1 = true;
//第二快 卷积匹配 //第二快 卷积匹配
string PathSql = SQlxK_HisenceWord.TwoblockPath; string PathSql = SQlxK_HisenceWord.TwoblockPath;
@ -2890,7 +3020,7 @@ namespace HisenceYoloDetection
Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect); Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect);
Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect); Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect);
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rectsql, rectDet, (bool)SQlxK_HisenceWord.TwoIFWhile, "D://Hisence//Test"); juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rectsql, rectDet, (bool)SQlxK_HisenceWord.TwoIFWhile, "D://Hisence//Test");
// juanjiMatch = true; // juanjiMatch = true;
if (!OneIF1 || !juanjiMatch) if (!OneIF1 || !juanjiMatch)
{ {
@ -2916,16 +3046,26 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.ThreeblockMainWord; SQLStr = SQlxK_HisenceWord.ThreeblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord);
if (!OneIF)
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); DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 3); Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 3);
*/
Defet_OnDetectionDone(OKMat, 3);
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 3); Defet_OnDetectionDone(OKMat, 3);
} }
@ -2940,9 +3080,15 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.FourblockMainWord; SQLStr = SQlxK_HisenceWord.FourblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
if (!OneIF)
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); DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
@ -2950,6 +3096,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 4); Defet_OnDetectionDone(OKMat, 4);
} }
@ -2964,9 +3111,14 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.FiveblockMainWord; SQLStr = SQlxK_HisenceWord.FiveblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
if (!OneIF) 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); DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
@ -2974,6 +3126,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 5); Defet_OnDetectionDone(OKMat, 5);
} }
} }
@ -2987,9 +3140,16 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.SixblockMainWord; SQLStr = SQlxK_HisenceWord.SixblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
if (!OneIF)
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.SixblockPath;
//第六块卷积设置一直为true
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
juanjiMatch = true;
if (!OneIF1 || !juanjiMatch)
{ {
OneIF = false;
// DisplayResult(mLcut); // DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
@ -2997,6 +3157,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 6); Defet_OnDetectionDone(OKMat, 6);
} }
@ -3011,9 +3172,14 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.SevenblockMainWord; SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
if (!OneIF) 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); //DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
@ -3021,6 +3187,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 7); Defet_OnDetectionDone(OKMat, 7);
} }
} }
@ -3034,9 +3201,14 @@ namespace HisenceYoloDetection
if (!saveimage) if (!saveimage)
{ {
SQLStr = SQlxK_HisenceWord.EightblockMainWord; SQLStr = SQlxK_HisenceWord.EightblockMainWord;
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord);
if (!OneIF) 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); // DisplayResult(mLcut);
//显示错误的板 //显示错误的板
// mLcut.ResultMap; // mLcut.ResultMap;
@ -3044,20 +3216,20 @@ namespace HisenceYoloDetection
} }
else else
{ {
OneIF = true;
Defet_OnDetectionDone(OKMat, 8); Defet_OnDetectionDone(OKMat, 8);
} }
} }
} }
break; break;
} }
using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", true)) string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString();
string txtLog = "D://Hisence//" + filename + "logsMatch.log";
using (StreamWriter sw = new StreamWriter(txtLog, true))
{ {
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
sw.WriteLine(filename + "\n"); sw.WriteLine("块" + blockIndex + "卷积匹配" + juanjiMatch);
if (blockIndex == "2")
{
sw.WriteLine("卷积匹配" + juanjiMatch);
}
sw.WriteLine("块" + blockIndex + "数据库" + SQLStr + "关键字" + MainWoidStr + "结果" + OneIF + "\n"); sw.WriteLine("块" + blockIndex + "数据库" + SQLStr + "关键字" + MainWoidStr + "结果" + OneIF + "\n");
sw.WriteLine("块" + blockIndex + " 所有字 " + TextWoidStr + "\n"); sw.WriteLine("块" + blockIndex + " 所有字 " + TextWoidStr + "\n");
@ -3109,5 +3281,20 @@ namespace HisenceYoloDetection
myLog("X轴停止归零", DateTime.Now); 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);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 0);
}
} }
} }

View File

@ -142,7 +142,7 @@
<value>733, 17</value> <value>733, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>31</value> <value>25</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <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"> <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距离 // 计算相似度相似度等于1减去标准化的Levenshtein距离
double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length)); double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length));
bool areEqual = false; bool areEqual = false;
if (similarity < 0.5) if (similarity < 0.9)
{ {
areEqual = false; areEqual = false;
} }
@ -227,10 +227,13 @@ namespace HisenceYoloDetection
} }
static bool AreMoreThanHalfEqual(string[] array1, string[] array2) static bool AreMoreThanHalfEqual(string[] array1, string[] array2)
{ {
string Sqltext = array1.Join("");
string Realtext = array2.Join("");
int io = 0; int io = 0;
foreach (string ch1 in array1)
foreach (char ch2 in Realtext)
{ {
foreach (string ch2 in array2) foreach (char ch1 in Sqltext)
{ {
if (ch1 == ch2) if (ch1 == ch2)
{ {
@ -249,7 +252,7 @@ namespace HisenceYoloDetection
//int intersectionCount = set1.Intersect(set2).Count(); //int intersectionCount = set1.Intersect(set2).Count();
// 判断交集数量是否超过一半 // 判断交集数量是否超过一半
return io > array1.Length / 2; return io >=Sqltext.Length / 2;
} }
public static bool StrMatch2(string SqlText, string DetText) public static bool StrMatch2(string SqlText, string DetText)
{ {
@ -277,7 +280,7 @@ namespace HisenceYoloDetection
Console.WriteLine("字符串中不包含数字"); Console.WriteLine("字符串中不包含数字");
} }
bool areEqual ; bool areEqual ;
if (numbers2.Length>2&& numbers.Length > 2) if (numbers2.Length>0&& numbers.Length > 0)
{ {
areEqual = AreMoreThanHalfEqual(numbers, numbers2); areEqual = AreMoreThanHalfEqual(numbers, numbers2);
} }

View File

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

View File

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