Compare commits

..

36 Commits

Author SHA1 Message Date
YZJ
44de774d4e 1 2024-08-26 18:07:19 +08:00
YZJ
f90eb75c3b 修改流程卡顿 2024-08-26 17:45:30 +08:00
YZJ
2913bc722c 最终版 2024-08-01 13:25:13 +08:00
df8736bcb1 关闭需要密码,通过按钮可直接打开图片文件路径 2024-08-01 00:22:40 +08:00
33fd534579 修改图像大小 2024-07-30 09:17:32 +08:00
df358a4e3a 展示实时旋钮图片 2024-07-29 17:35:37 +08:00
71997776cf 修改结果框 2024-07-29 13:45:55 +08:00
b4c7a6c6cb 部分修改 2024-07-27 11:29:48 +08:00
YZJ
b6dce9e5cf 可正常检测,旋钮颜色判断和底板颜色有待修改 2024-07-25 17:27:32 +08:00
8281971cee 机身倾斜和旋钮颜色判断 2024-07-24 23:56:47 +08:00
YZJ
f86733cc91 可以自动插入,将来要加按钮颜色判别和机身倾斜判断 2024-07-24 15:56:30 +08:00
295d30b49f 插入流程更改 2024-07-24 13:07:15 +08:00
618c799818 增加旋钮识别 2024-07-24 10:48:05 +08:00
3a9d6c5e7e 优化界面,增加自动插入,原始图像遮挡旋钮,post请求当天日期。 2024-07-23 00:22:27 +08:00
YZJ
812cfd725f 修改放行逻辑(未修改 2024-07-22 17:21:42 +08:00
YZJ
267332bad5 修改关闭检测 2024-07-22 16:50:01 +08:00
YZJ
f1a9e75917 修改流程 2024-07-15 17:45:27 +08:00
YZJ
791bfb85d2 重新修改 2024-07-15 17:15:47 +08:00
YZJ
feeda6a550 修改mes 2024-07-15 17:15:28 +08:00
9a89e11ef9 7/14号测试 2024-07-14 16:10:14 +08:00
YZJ
a99c3b275d 程序无法正常运行,代码中数据改动较多 2024-07-13 13:22:37 +08:00
YZJ
43a8668e7c 程序无法正常运行,代码中数据改动较多 2024-07-13 13:10:27 +08:00
756d23229c PLC报警灯地址已修改 2024-07-09 21:59:38 +08:00
08ab697a02 修改逻辑 2024-07-09 17:06:36 +08:00
YZJ
ca2403b323 修改Mes逻辑 2024-07-09 16:56:45 +08:00
19da00146e 修改读码器 2024-07-08 16:29:40 +08:00
15df28b3b4 修改读码器和MES系统对接 2024-07-05 16:04:47 +08:00
eb55c5b784 修改图片闪烁,yolo先定位在识别,误检率和报警灯 2024-07-05 11:22:41 +08:00
YZJ
a018a8f54d 图片闪烁,关闭阻塞问题未解决 2024-07-01 11:39:19 +08:00
YZJ
33b32a6c92 图片闪烁与关闭阻塞未解决 2024-07-01 11:33:35 +08:00
YZJ
a6d2f87095 测试一二块基本没问题版本 2024-06-28 17:50:44 +08:00
d3a08b35f7 修改字符相似度匹配 2024-06-27 18:16:27 +08:00
733500850e 更改了卷积匹配(可以试一试,不一定好用) 2024-06-27 18:09:39 +08:00
2db802c899 修改界面 和遮挡第一块显示NG 2024-06-27 16:25:52 +08:00
d82f308fed 更改字符比对 2024-06-27 14:40:37 +08:00
YZJ
e2dc220aaf 修改冲突 2024-06-27 13:48:39 +08:00
12 changed files with 3184 additions and 1613 deletions

View File

@ -1,20 +1,70 @@
using OpenCvSharp;
using OpenCvSharp.Flann;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size;
using System;
using OpenCvSharp;
using OpenCvSharp.Features2D;
using OpenCvSharp.Flann;
using System.Drawing;
namespace HisenceYoloDetection
{
public static class CheckDiffSciHelper
public static class CheckDiffSciHelper
{
public static Mat ProcessImage(Mat image, Rect fillRect)
{
// 获取图像尺寸
int width = image.Width;
int height = image.Height;
// 定义左下角 30x30 矩形框
int rectSize = 30;
int rectX = 0;
int rectY = height - rectSize; // 确保是左下角
// 检查左下角矩形框是否在图像范围内
if (rectY < 0 || rectX < 0 || rectSize > width || rectSize > height)
{
Console.WriteLine("图像尺寸不足以获取指定区域");
return image;
}
// 定义感兴趣区域 (ROI) 并计算其平均颜色
Rect roi = new Rect(rectX, rectY, rectSize, rectSize);
Mat roiMat = new Mat(image, roi);
Scalar meanColor = Cv2.Mean(roiMat);
// 创建 Scalar 类型的颜色填充
Scalar fillColor = new Scalar(meanColor.Val0, meanColor.Val1, meanColor.Val2);
// 修改 fillRect 的 Y 和 Height 属性以覆盖整个图像的高度
fillRect.Y = 0; // 起始位置为顶部
fillRect.Height = height; // 高度覆盖整个图像
// 检查填充矩形是否在图像范围内
if (fillRect.X < 0 || fillRect.X + fillRect.Width > width)
{
Console.WriteLine("填充区域超出图像范围");
return image;
}
// 使用 OpenCV 的 rectangle 函数进行填充
Cv2.Rectangle(image, fillRect.TopLeft, fillRect.BottomRight, fillColor, Cv2.FILLED);
return image;
}
/// <summary>
///
/// </summary>
@ -22,40 +72,45 @@ namespace HisenceYoloDetection
/// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</param>
public static bool CheckDiffSci(string path1, Mat MatDet,Rect sqlrect,Rect detrect, bool IfWhiteWord, string saveDir)
public static bool CheckDiffSci(string path1, Mat MatDet, ref Mat ResultMat,Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir,string SN)
{
// 读取和处理第一张图片
// 读取和处理第一张图片。。
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));
// Cv2.Resize(img1, img1, new Size(550, 270));
img1 = ProcessImage(img1, sqlrect);
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
{
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
}
// 读取和处理第二张图片
Mat img2 = MatDet.Clone();
ResultMat= MatDet.Clone();
if (img2.Empty())
{
// Console.WriteLine($"Error loading image {path2}");
// Console.WriteLine($"Error loading image {path2}");
return false;
}
// Cv2.Resize(img2, img2, new Size(550, 270));
// Cv2.Resize(img2, img2, new Size(550, 270));
img2 = ProcessImage(img2, detrect);
Rect bottomleftRect= new Rect(0,img1.Height-30,30,30);
Scalar avgColor1 = Cv2.Mean(new Mat(img1,bottomleftRect));
Mat gimg2 = new Mat();
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
Mat thr2 = new Mat();
@ -68,14 +123,15 @@ namespace HisenceYoloDetection
{
Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
}
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
//Rect area2 = new Rect(148,30,229,222);
sqlrect.Width += 20;
sqlrect.Height+= 100;
detrect.Width += 20;
detrect.Height+=100;
Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord)
{
matCutblack1.SetTo(Scalar.Black);
@ -95,17 +151,17 @@ namespace HisenceYoloDetection
}
Cv2.Resize(thr1, thr1, new Size(550, 270));
Cv2.Resize(thr2, thr2, new Size(550, 270));
DateTime dt= DateTime.Now;
string filename= dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
DateTime dt = DateTime.Now;
string filename = SN;
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr1.png");
// string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
// 保存结果
Cv2.ImWrite(savePath4, thr1);
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png");
//Cv2.ImWrite(savePath4, thr1);
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
// 保存结果
Cv2.ImWrite(savePath3, thr2);
//Cv2.ImWrite(savePath3, thr2);
// 创建卷积核
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
@ -126,12 +182,12 @@ namespace HisenceYoloDetection
//string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result1.png");
//// 保存结果
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.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");
////保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
//Cv2.ImWrite(savePath, final_result2);
@ -145,10 +201,17 @@ namespace HisenceYoloDetection
Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, devIMG_);
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
//// 保存结果
//Cv2.ImWrite(savePathd, devIMG);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
//// 保存结果
//Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG, devIMG, 20, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 20, 255, ThresholdTypes.Binary);
// 结合差异
Mat sumIMG = new Mat();
@ -160,36 +223,60 @@ namespace HisenceYoloDetection
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);
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);
// 框选轮廓
//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);
}
else
{
Rect boundingRect = Cv2.BoundingRect(contour);
Cv2.Resize(img2, img2, new Size(550, 270));
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
isMatch= false;
isMatch = false;
string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ng",filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
CheckDiffSciHelper1.ResizeImage(savePath2, savePath2, 640, 480, 75);
ResultMat = img2.Clone();
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);
}
}
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);
// 新增的白色面积占比判断
double whiteArea1 = Cv2.CountNonZero(thr1);
double whiteArea2 = Cv2.CountNonZero(thr2);
double ratio1 = whiteArea1 / (thr1.Rows * thr1.Cols);
double ratio2 = whiteArea2 / (thr2.Rows * thr2.Cols);
if (Math.Abs(ratio1 - ratio2) >= 0.90)
{
isMatch = true;
}
return isMatch;
}
public static Rect strChangeRect(string strrect)
{
if (!string.IsNullOrEmpty(strrect))
@ -202,14 +289,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);
@ -220,123 +308,324 @@ 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
{
/// <summary>
///
/// </summary>
/// <param name="path1">标准图像</param>
/// <param name="path2">要对比的图像</param>
/// <param name="IfWhiteWord"> 白板黑字为true </param>
/// <param name="saveDir">存储路径</param>
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir,string SN)
{
// 读取和处理第一张图片
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
// if (IfWhiteWord)
// {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// }
// else
// {
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// }
if (img1.Empty())
{
Console.WriteLine($"Error loading image {path1}");
return false;
}
// Cv2.Resize(img1, img1, new Size(550, 270));
img1 = RemoveBorders(img1);
Mat gimg1 = new Mat();
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
Mat thr1 = new Mat();
if (IfWhiteWord)
{
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
}
else
{
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
}
// string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr1.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath4, thr1);
// // 读取和处理第二张图片
// Mat img2 = Cv2.ImRead(path2, ImreadModes.Color);
// if (img2.Empty())
// {
// Console.WriteLine($"Error loading image {path2}");
// return;
// }
// Cv2.Resize(img2, img2, new Size(550, 270));
// Mat gimg2 = new Mat();
// Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
// Mat thr2 = new Mat();
// //Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// if (IfWhiteWord)
// {
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
// }
// else
// {
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// }
// // Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
// string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr2.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath3, thr2);
// 读取和处理第二张图片
Mat img2 = MatDet.Clone();
if (img2.Empty())
{
// Console.WriteLine($"Error loading image {path2}");
return false;
}
// Cv2.Resize(img2, img2, new Size(550, 270));
img2 = RemoveBorders(img2);
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);
}
// // 创建卷积核
// 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 = SN;
// 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 kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
// Mat blackhatImg = new Mat();
// Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
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));
// // 处理轮廓和保存结果
// Point[][] contours = new Point[10000][];
// Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
// foreach (var contour in contours)
// {
// if (Cv2.ContourArea(contour) <= 100)
// {
// Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
// // 框选轮廓
// }
// else
// {
// Rect boundingRect = Cv2.BoundingRect(contour);
// Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
// }
// }
// string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_Rect.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath2, img2);
// string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// // 保存结果
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
// Cv2.ImWrite(savePath, blackhatImg);
//}
// 应用卷积
Mat final_result1 = new Mat();
Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result1, final_result1, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Mat final_result2 = new Mat();
Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result2, final_result2, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//裁剪才行
//string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result1.png");
//// 保存结果
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
//Cv2.ImWrite(savePath2, final_result1);
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result2.png");
//// 保存结果
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
//Cv2.ImWrite(savePath, final_result2);
// 计算图像差异
Mat devIMG = new Mat();
Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, devIMG_);
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
// 保存结果
// Cv2.ImWrite(savePathd, devIMG);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
// 保存结果
//Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 8, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 8, 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) <= 500)
{
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);
//ResizeImage(savePath2, savePath2, 640, 480, 75);
//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 void ResizeImage(string inputPath, string outputPath, int newWidth, int newHeight, int quality)
{
// 加载原始图像
using (Mat originalImage = Cv2.ImRead(inputPath))
{
// 创建一个Mat对象用于存储缩放后的图像
using (Mat resizedImage = new Mat())
{
// 缩放图像
Cv2.Resize(originalImage, resizedImage, new OpenCvSharp.Size(newWidth, newHeight));
// 保存图像为JPEG格式并设置压缩质量
SaveJpeg(outputPath, resizedImage, quality);
Console.WriteLine($"Image saved to {outputPath}");
}
}
}
static void SaveJpeg(string path, Mat image, int quality)
{
// 设置JPEG编码参数
var encodeParams = new[] { new ImageEncodingParam(ImwriteFlags.JpegQuality, quality) };
// 保存图像
Cv2.ImWrite(path, image, encodeParams);
}
static Mat RemoveBorders(Mat image)
{
// 将图像转换为灰度图
Mat grayImage = new Mat();
Cv2.CvtColor(image, grayImage, ColorConversionCodes.BGR2GRAY);
// 使用自适应二值化将图像变为黑白图
Mat binaryImage = new Mat();
Cv2.AdaptiveThreshold(grayImage, binaryImage, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 11, 2);
// 反转颜色
Mat invertedBinaryImage = new Mat();
Cv2.BitwiseNot(binaryImage, invertedBinaryImage);
// 查找轮廓
Point[][] contours;
HierarchyIndex[] hierarchy;
Cv2.FindContours(invertedBinaryImage, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
// 找到包含最大面积的轮廓
double maxArea = 0;
Point[] maxContour = null;
foreach (var contour in contours)
{
double area = Cv2.ContourArea(contour);
if (area > maxArea)
{
maxArea = area;
maxContour = contour;
}
}
if (maxContour == null)
{
Console.WriteLine("未找到有效轮廓!");
return image;
}
// 找到平行四边形的四个顶点
Point[] approx = Cv2.ApproxPolyDP(maxContour, Cv2.ArcLength(maxContour, true) * 0.02, true);
Point2f[] srcPoints = approx.Select(p => new Point2f(p.X, p.Y)).ToArray();
if (srcPoints.Length != 4)
{
Console.WriteLine("未找到平行四边形的四个顶点!");
return image;
}
// 按顺时针顺序对顶点进行排序
srcPoints = OrderPoints(srcPoints);
// 确定目标图像的四个顶点
Point2f[] dstPoints = new Point2f[]
{
new Point2f(0, 0),
new Point2f(image.Width - 1, 0),
new Point2f(image.Width - 1, image.Height - 1),
new Point2f(0, image.Height - 1)
};
// 计算透视变换矩阵
Mat transformMatrix = Cv2.GetPerspectiveTransform(srcPoints, dstPoints);
// 应用透视变换
Mat warpedImage = new Mat();
Cv2.WarpPerspective(image, warpedImage, transformMatrix, new Size(image.Width, image.Height));
return warpedImage;
}
private static Point2f[] OrderPoints(Point2f[] points)
{
// 对顶点进行排序,顺时针顺序
Point2f[] orderedPoints = new Point2f[4];
// 计算质心
Point2f center = new Point2f(points.Average(p => p.X), points.Average(p => p.Y));
foreach (var point in points)
{
if (point.X < center.X && point.Y < center.Y)
orderedPoints[0] = point; // 左上
else if (point.X > center.X && point.Y < center.Y)
orderedPoints[1] = point; // 右上
else if (point.X > center.X && point.Y > center.Y)
orderedPoints[2] = point; // 右下
else if (point.X < center.X && point.Y > center.Y)
orderedPoints[3] = point; // 左下
}
return orderedPoints;
}
}
}
}
}

87
HisenceYoloDetection/Form2.Designer.cs generated Normal file
View File

@ -0,0 +1,87 @@
namespace HisenceYoloDetection
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
button1 = new Button();
textBox1 = new TextBox();
label1 = new Label();
SuspendLayout();
//
// button1
//
button1.Location = new Point(192, 58);
button1.Margin = new Padding(2, 2, 2, 2);
button1.Name = "button1";
button1.Size = new Size(71, 24);
button1.TabIndex = 0;
button1.Text = "验证";
button1.UseVisualStyleBackColor = true;
//
// textBox1
//
textBox1.Location = new Point(143, 24);
textBox1.Margin = new Padding(2, 2, 2, 2);
textBox1.Name = "textBox1";
textBox1.Size = new Size(173, 23);
textBox1.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(58, 24);
label1.Margin = new Padding(2, 0, 2, 0);
label1.Name = "label1";
label1.Size = new Size(68, 17);
label1.TabIndex = 2;
label1.Text = "输入密码:";
label1.Click += label1_Click;
//
// Form2
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(429, 92);
Controls.Add(label1);
Controls.Add(textBox1);
Controls.Add(button1);
Margin = new Padding(2, 2, 2, 2);
Name = "Form2";
Text = "验证身份";
Load += Form2_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button button1;
private TextBox textBox1;
private Label label1;
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HisenceYoloDetection
{
public partial class Form2 : Form
{
public string EnteredPassword { get; private set; }
public Form2()
{
InitializeComponent();
button1.Click += button1_Click; // 订阅按钮点击事件
}
private void button1_Click(object sender, EventArgs e)
{
EnteredPassword = textBox1.Text;
DialogResult = DialogResult.OK;
Close();
}
private void Form2_Load(object sender, EventArgs e)
{
CenterToScreen();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -2,16 +2,18 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net7.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>AnyCPU;X64</Platforms>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationIcon>bin\X64\Debug\net7.0-windows\Logo.ico</ApplicationIcon>
<AppendTargetFrameworkToOutputPath>output</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<None Remove="MainForm.resx~RF4efdcc4.TMP" />
<None Remove="ManagerModelHelper.cs~RF97ff9f.TMP" />
<None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" />
</ItemGroup>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>569, 17</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
@ -135,14 +138,11 @@
<metadata name="timer6.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>477, 17</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>569, 17</value>
</metadata>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>733, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>31</value>
<value>25</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@ -104,83 +104,7 @@ namespace HisenceYoloDetection
return cslist;
}
public static bool IsMatchSQLText(ref Mat detMat, ref XK_HisenceWord XKSQL, ref XK_HisenceWord XKDet)
{
try
{
string TwoRectstr = XKSQL.TwoRect;
string oneBlockWordSql = XKSQL.OneblockMainWord;
string twoBlockWordSql = XKSQL.TwoblockMainWord;
string threeBlockWordSql = XKSQL.ThreeblockMainWord;
string fourBlockWordSql = XKSQL.FourblockMainWord;
string fiveBlockWordSql = XKSQL.FiveblockMainWord;
string sixBlockWordSql = XKSQL.SixblockMainWord;
string sevenBlockWordSql = XKSQL.SevenblockMainWord;
string eightBlockWordSql = XKSQL.EightblockMainWord;
string oneBlockWordDet = XKDet.OneblockMainWord;
string twoBlockWordDet = XKDet.TwoblockMainWord;
string threeBlockWordDet = XKDet.ThreeblockMainWord;
string fourBlockWordDet = XKDet.FourblockMainWord;
string fiveBlockWordDet = XKDet.FiveblockMainWord;
string sixBlockWordDet = XKDet.SixblockMainWord;
string sevenBlockWordDet = XKDet.SevenblockMainWord;
string eightBlockWordDet = XKDet.EightblockMainWord;
bool OneIF = isMatchStr(oneBlockWordSql, oneBlockWordDet);
bool TwoIF = isMatchStr(twoBlockWordSql, twoBlockWordDet);
bool ThreeIF = isMatchStr(threeBlockWordSql, threeBlockWordDet);
bool FourIF = isMatchStr(fourBlockWordSql, fourBlockWordDet);
bool FiveIF = isMatchStr(fiveBlockWordSql, fiveBlockWordDet);
bool SixIF = isMatchStr(sixBlockWordSql, sixBlockWordDet);
bool SenvenIF = isMatchStr(sevenBlockWordSql, sevenBlockWordDet);
bool EightIF = isMatchStr(eightBlockWordSql, eightBlockWordDet);
//第二快 卷积匹配
string PathSql = XKSQL.TwoblockPath;
//
Rect rectsql = CheckDiffSciHelper.strChangeRect(TwoRectstr);
Rect rectDet = CheckDiffSciHelper.strChangeRect(XKDet.TwoRect);
bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet, (bool)XKSQL.TwoIFWhile, "D://Test");
DateTime dt = DateTime.Now;
using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", 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(oneBlockWordSql + " " + oneBlockWordDet + "\n");
sw.WriteLine(twoBlockWordSql + " " + twoBlockWordDet + "\n");
sw.WriteLine(threeBlockWordSql + " " + threeBlockWordDet + "\n");
sw.WriteLine(fourBlockWordSql + " " + fourBlockWordDet + "\n");
sw.WriteLine(fiveBlockWordSql + " " + fiveBlockWordDet + "\n");
sw.WriteLine(sixBlockWordSql + " " + sixBlockWordDet + "\n");
sw.WriteLine(sevenBlockWordSql + " " + sevenBlockWordDet + "\n");
sw.WriteLine(eightBlockWordSql + " " + eightBlockWordDet + "\n");
sw.WriteLine(" 卷积匹配 " + twoif2 + "\n");
sw.Flush();
}
//第三块区域一直都是false
if (OneIF && TwoIF && ThreeIF && FourIF && FiveIF && SixIF && SenvenIF && EightIF && twoif2)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public static bool StrMatch(string SqlText,string DetText)
{
// 计算Levenshtein距离
@ -189,7 +113,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;
}
@ -227,10 +151,13 @@ namespace HisenceYoloDetection
}
static bool AreMoreThanHalfEqual(string[] array1, string[] array2)
{
string Sqltext = array1.Join("");
string Realtext = array2.Join("");
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)
{
@ -249,7 +176,7 @@ namespace HisenceYoloDetection
//int intersectionCount = set1.Intersect(set2).Count();
// 判断交集数量是否超过一半
return io > array1.Length / 2;
return io >=Sqltext.Length / 2;
}
public static bool StrMatch2(string SqlText, string DetText)
{
@ -277,7 +204,7 @@ namespace HisenceYoloDetection
Console.WriteLine("字符串中不包含数字");
}
bool areEqual ;
if (numbers2.Length>2&& numbers.Length > 2)
if (numbers2.Length>0&& numbers.Length > 0)
{
areEqual = AreMoreThanHalfEqual(numbers, numbers2);
}

View File

@ -18,9 +18,9 @@ namespace HisenceYoloDetection
public void Strart()
{
client = new TcpClient();
client.Host = "192.168.3.100";
client.Host = "192.168.3.100";
client.Port= 9004;
//client.Host = "127.0.0.1";
//client.Host = "127.0.0.1";
//client.Port = 9000;
client.Connect();

View File

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

View File

@ -5,8 +5,14 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<BaseOutputPath>.\bin\X64\Debug</BaseOutputPath>
<!--<BaseOutputPath>.\bin\X64\Debug</BaseOutputPath>-->
<OutputType>Library</OutputType>
<AppendTargetFrameworkToOutputPath>output</AppendTargetFrameworkToOutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup>
<ItemGroup>