Compare commits
9 Commits
master
...
dev_featur
Author | SHA1 | Date | |
---|---|---|---|
eb55c5b784 | |||
|
a018a8f54d | ||
|
33b32a6c92 | ||
|
a6d2f87095 | ||
d3a08b35f7 | |||
733500850e | |||
2db802c899 | |||
d82f308fed | |||
|
e2dc220aaf |
@ -1,10 +1,12 @@
|
||||
using OpenCvSharp;
|
||||
using Sunny.UI.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using Point = OpenCvSharp.Point;
|
||||
using Size = OpenCvSharp.Size;
|
||||
|
||||
@ -12,9 +14,8 @@ using Size = OpenCvSharp.Size;
|
||||
|
||||
namespace HisenceYoloDetection
|
||||
{
|
||||
public static class CheckDiffSciHelper
|
||||
public static class CheckDiffSciHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@ -22,40 +23,40 @@ namespace HisenceYoloDetection
|
||||
/// <param name="path2">要对比的图像</param>
|
||||
/// <param name="IfWhiteWord"> 白板黑字为true </param>
|
||||
/// <param name="saveDir">存储路径</param>
|
||||
public static bool CheckDiffSci(string path1, Mat MatDet,Rect sqlrect,Rect detrect, bool IfWhiteWord, string saveDir)
|
||||
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
|
||||
{
|
||||
// 读取和处理第一张图片
|
||||
// 读取和处理第一张图片。。
|
||||
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
|
||||
if (img1.Empty())
|
||||
{
|
||||
Console.WriteLine($"Error loading image {path1}");
|
||||
return false;
|
||||
}
|
||||
// Cv2.Resize(img1, img1, new Size(550, 270));
|
||||
// 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
|
||||
{
|
||||
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 读取和处理第二张图片
|
||||
Mat img2 = 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));
|
||||
Mat gimg2 = new Mat();
|
||||
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
|
||||
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);
|
||||
|
||||
|
||||
|
||||
//Rect area2 = new Rect(148,30,229,222);
|
||||
sqlrect.Width += 20;
|
||||
sqlrect.Height += 60;
|
||||
detrect.Width += 20;
|
||||
detrect.Height += 60;
|
||||
Mat matCutblack1 = new Mat(thr1, sqlrect);
|
||||
if (IfWhiteWord)
|
||||
{
|
||||
@ -95,17 +96,17 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
Cv2.Resize(thr1, thr1, new Size(550, 270));
|
||||
Cv2.Resize(thr2, thr2, new Size(550, 270));
|
||||
DateTime dt= DateTime.Now;
|
||||
string filename= dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
DateTime dt = DateTime.Now;
|
||||
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
|
||||
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr1.png");
|
||||
// 保存结果
|
||||
|
||||
Cv2.ImWrite(savePath4, thr1);
|
||||
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png");
|
||||
// 保存结果
|
||||
|
||||
Cv2.ImWrite(savePath3, thr2);
|
||||
//string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePath4, thr1);
|
||||
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePath3, thr2);
|
||||
|
||||
// 创建卷积核
|
||||
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
|
||||
@ -145,10 +146,17 @@ namespace HisenceYoloDetection
|
||||
Mat devIMG_ = new Mat();
|
||||
Cv2.Subtract(final_result1, final_result2, devIMG);
|
||||
Cv2.Subtract(final_result2, final_result1, devIMG_);
|
||||
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePathd, devIMG);
|
||||
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePathd1, devIMG_);
|
||||
// 对差异图像应用阈值
|
||||
Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary);
|
||||
Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary);
|
||||
Cv2.Threshold(devIMG, devIMG, 20, 255, ThresholdTypes.Binary);
|
||||
Cv2.Threshold(devIMG_, devIMG_, 20, 255, ThresholdTypes.Binary);
|
||||
|
||||
// 结合差异
|
||||
Mat sumIMG = new Mat();
|
||||
@ -160,36 +168,46 @@ 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\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath2, img2);
|
||||
string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath, blackhatImg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect boundingRect = Cv2.BoundingRect(contour);
|
||||
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
|
||||
isMatch= false;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Rect strChangeRect(string strrect)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(strrect))
|
||||
@ -202,14 +220,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 +239,198 @@ namespace HisenceYoloDetection
|
||||
string strrect = rectsql.Join(",");
|
||||
return strrect;
|
||||
}
|
||||
//public static void CheckDiffSci(string path1, string path2, bool IfWhiteWord, string saveDir)
|
||||
//{
|
||||
// // 读取和处理第一张图片
|
||||
// Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
|
||||
// if (img1.Empty())
|
||||
// {
|
||||
// Console.WriteLine($"Error loading image {path1}");
|
||||
// return;
|
||||
// }
|
||||
// Cv2.Resize(img1, img1, new Size(550, 270));
|
||||
// Mat gimg1 = new Mat();
|
||||
// Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
|
||||
// Mat thr1 = new Mat();
|
||||
public static class CheckDiffSciHelper1
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path1">标准图像</param>
|
||||
/// <param name="path2">要对比的图像</param>
|
||||
/// <param name="IfWhiteWord"> 白板黑字为true </param>
|
||||
/// <param name="saveDir">存储路径</param>
|
||||
public static bool CheckDiffSci(string path1, Mat MatDet, Rect sqlrect, Rect detrect, bool IfWhiteWord, string saveDir)
|
||||
{
|
||||
// 读取和处理第一张图片
|
||||
Mat img1 = Cv2.ImRead(path1, ImreadModes.Color);
|
||||
if (img1.Empty())
|
||||
{
|
||||
Console.WriteLine($"Error loading image {path1}");
|
||||
return false;
|
||||
}
|
||||
// Cv2.Resize(img1, img1, new Size(550, 270));
|
||||
Mat gimg1 = new Mat();
|
||||
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
|
||||
Mat thr1 = new Mat();
|
||||
|
||||
// if (IfWhiteWord)
|
||||
// {
|
||||
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
|
||||
// }
|
||||
if (IfWhiteWord)
|
||||
{
|
||||
Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv2.Threshold(gimg1, thr1, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu
|
||||
}
|
||||
|
||||
|
||||
// string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr1.png");
|
||||
// // 保存结果
|
||||
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
// Cv2.ImWrite(savePath4, thr1);
|
||||
|
||||
// // 读取和处理第二张图片
|
||||
// Mat img2 = Cv2.ImRead(path2, ImreadModes.Color);
|
||||
// if (img2.Empty())
|
||||
// {
|
||||
// Console.WriteLine($"Error loading image {path2}");
|
||||
// return;
|
||||
// }
|
||||
// Cv2.Resize(img2, img2, new Size(550, 270));
|
||||
// Mat gimg2 = new Mat();
|
||||
// Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
|
||||
// Mat thr2 = new Mat();
|
||||
// //Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
// if (IfWhiteWord)
|
||||
// {
|
||||
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
|
||||
// }
|
||||
// // Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
|
||||
|
||||
// string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_thr2.png");
|
||||
// // 保存结果
|
||||
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
// Cv2.ImWrite(savePath3, thr2);
|
||||
// 读取和处理第二张图片
|
||||
Mat img2 = MatDet.Clone();
|
||||
if (img2.Empty())
|
||||
{
|
||||
// Console.WriteLine($"Error loading image {path2}");
|
||||
return false;
|
||||
}
|
||||
// Cv2.Resize(img2, img2, new Size(550, 270));
|
||||
Mat gimg2 = new Mat();
|
||||
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
|
||||
Mat thr2 = new Mat();
|
||||
//Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
if (IfWhiteWord)
|
||||
{
|
||||
Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv2.Threshold(gimg2, thr2, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu
|
||||
}
|
||||
|
||||
// // 创建卷积核
|
||||
// Mat filter1 = new Mat(17, 17, MatType.CV_32F, new Scalar(0));
|
||||
// filter1.Row(8).SetTo(new Scalar(0.025));
|
||||
// filter1.Col(8).SetTo(new Scalar(0.025));
|
||||
|
||||
// // 应用卷积
|
||||
// Mat final_result1 = new Mat();
|
||||
// Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
// Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
//Rect area2 = new Rect(148,30,229,222);
|
||||
sqlrect.Width += 20;
|
||||
sqlrect.Height += 20;
|
||||
detrect.Width += 20;
|
||||
detrect.Height += 20;
|
||||
Mat matCutblack1 = new Mat(thr1, sqlrect);
|
||||
if (IfWhiteWord)
|
||||
{
|
||||
matCutblack1.SetTo(Scalar.Black);
|
||||
}
|
||||
else
|
||||
{
|
||||
matCutblack1.SetTo(Scalar.Black);
|
||||
}
|
||||
Mat matCutblack2 = new Mat(thr2, detrect);
|
||||
if (IfWhiteWord)
|
||||
{
|
||||
matCutblack2.SetTo(Scalar.Black);
|
||||
}
|
||||
else
|
||||
{
|
||||
matCutblack2.SetTo(Scalar.Black);
|
||||
}
|
||||
Cv2.Resize(thr1, thr1, new Size(845, 498));
|
||||
Cv2.Resize(thr2, thr2, new Size(845, 498));
|
||||
DateTime dt = DateTime.Now;
|
||||
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
|
||||
// Mat final_result2 = new Mat();
|
||||
// Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
// Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
// Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
//string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
|
||||
//// 保存结果
|
||||
|
||||
// // 计算图像差异
|
||||
// Mat devIMG = new Mat();
|
||||
// Mat devIMG_ = new Mat();
|
||||
// Cv2.Subtract(final_result1, final_result2, devIMG);
|
||||
// Cv2.Subtract(final_result2, final_result1, devIMG_);
|
||||
//Cv2.ImWrite(savePath4, thr1);
|
||||
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
|
||||
//// 保存结果
|
||||
|
||||
// // 对差异图像应用阈值
|
||||
// Cv2.Threshold(devIMG, devIMG, 50, 255, ThresholdTypes.Binary);
|
||||
// Cv2.Threshold(devIMG_, devIMG_, 50, 255, ThresholdTypes.Binary);
|
||||
//Cv2.ImWrite(savePath3, thr2);
|
||||
|
||||
// // 结合差异
|
||||
// Mat sumIMG = new Mat();
|
||||
// Cv2.Add(devIMG, devIMG_, sumIMG);
|
||||
// 创建卷积核
|
||||
|
||||
Mat filter1 = new Mat(15,15, MatType.CV_32F, new Scalar(0));
|
||||
filter1.Row(7).SetTo(new Scalar(0.025));
|
||||
filter1.Col(7).SetTo(new Scalar(0.025));
|
||||
|
||||
// // 应用形态学操作
|
||||
// Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
|
||||
// Mat blackhatImg = new Mat();
|
||||
// Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
|
||||
|
||||
// 应用卷积
|
||||
Mat final_result1 = new Mat();
|
||||
Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
|
||||
//Cv2.Filter2D(final_result1, final_result1, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
|
||||
// // 处理轮廓和保存结果
|
||||
// Point[][] contours = new Point[10000][];
|
||||
// Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
|
||||
Mat final_result2 = new Mat();
|
||||
Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
|
||||
//Cv2.Filter2D(final_result2, final_result2, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
|
||||
//裁剪才行
|
||||
|
||||
// foreach (var contour in contours)
|
||||
// {
|
||||
// if (Cv2.ContourArea(contour) <= 100)
|
||||
// {
|
||||
// Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
|
||||
// // 框选轮廓
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Rect boundingRect = Cv2.BoundingRect(contour);
|
||||
// Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
|
||||
// }
|
||||
// }
|
||||
// string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_Rect.png");
|
||||
// // 保存结果
|
||||
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
// Cv2.ImWrite(savePath2, img2);
|
||||
// string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
// // 保存结果
|
||||
// //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
// Cv2.ImWrite(savePath, blackhatImg);
|
||||
//}
|
||||
//string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result1.png");
|
||||
//// 保存结果
|
||||
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
//Cv2.ImWrite(savePath2, final_result1);
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_final_result2.png");
|
||||
//// 保存结果
|
||||
////string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
//Cv2.ImWrite(savePath, final_result2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 计算图像差异
|
||||
Mat devIMG = new Mat();
|
||||
Mat devIMG_ = new Mat();
|
||||
Cv2.Subtract(final_result1, final_result2, devIMG);
|
||||
Cv2.Subtract(final_result2, final_result1, devIMG_);
|
||||
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePathd, devIMG);
|
||||
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePathd1, devIMG_);
|
||||
// 对差异图像应用阈值
|
||||
Cv2.Threshold(devIMG, devIMG, 45, 255, ThresholdTypes.Binary);
|
||||
Cv2.Threshold(devIMG_, devIMG_, 45, 255, ThresholdTypes.Binary);
|
||||
|
||||
// 结合差异
|
||||
Mat sumIMG = new Mat();
|
||||
Cv2.Add(devIMG, devIMG_, sumIMG);
|
||||
//string savePaths = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "sumIMG.png");
|
||||
//// 保存结果
|
||||
|
||||
//Cv2.ImWrite(savePaths, sumIMG);
|
||||
// 应用形态学操作
|
||||
Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
|
||||
Mat blackhatImg = new Mat();
|
||||
Cv2.Dilate(sumIMG, blackhatImg, kernelCL);
|
||||
|
||||
// 处理轮廓和保存结果
|
||||
Point[][] contours = new Point[10000][];
|
||||
Cv2.FindContours(blackhatImg, out contours, out _, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
|
||||
bool isMatch = true;
|
||||
foreach (var contour in contours)
|
||||
{
|
||||
if (Cv2.ContourArea(contour) <= 100)
|
||||
{
|
||||
Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
|
||||
// 框选轮廓
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect boundingRect = Cv2.BoundingRect(contour);
|
||||
Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2);
|
||||
isMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath2, img2);
|
||||
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath, blackhatImg);
|
||||
return isMatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="MainForm.resx~RF4efdcc4.TMP" />
|
||||
<None Remove="ManagerModelHelper.cs~RF97ff9f.TMP" />
|
||||
<None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" />
|
||||
</ItemGroup>
|
||||
|
1263
HisenceYoloDetection/MainForm.Designer.cs
generated
1263
HisenceYoloDetection/MainForm.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,8 @@ using OpenCvSharp;
|
||||
using OpenCvSharp.Dnn;
|
||||
using OpenCvSharp.Extensions;
|
||||
using OpenCvSharp.XFeatures2D;
|
||||
using Sunny.UI;
|
||||
using Sunny.UI.Win32;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -20,9 +22,11 @@ using System.Net;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using XKRS.Device.SimboVision.SimboHelper;
|
||||
using XKRS.UI;
|
||||
using static HisenceYoloDetection.CheckDiffSciHelper;
|
||||
using static HisenceYoloDetection.MainForm;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
@ -61,6 +65,9 @@ namespace HisenceYoloDetection
|
||||
List<XKHisence> xKHisences = new List<XKHisence>();
|
||||
|
||||
static AutoResetEvent myResetEvent = new AutoResetEvent(false);
|
||||
|
||||
AutoResetEvent _runHandleBefore = new AutoResetEvent(false);
|
||||
ManualResetEvent _runHandleAfter = new ManualResetEvent(false);
|
||||
bool PLC545 = false;
|
||||
|
||||
bool PLC548 = false;
|
||||
@ -100,7 +107,11 @@ namespace HisenceYoloDetection
|
||||
string Cam1OnePath = "";
|
||||
string Cam1TwoPath = "";
|
||||
string ModelChangePath = "";
|
||||
|
||||
//报警灯
|
||||
string GreenLightingAdress = "";
|
||||
string YellowLightingAdress = "";
|
||||
string RedLightingAdress = "";
|
||||
string WaringAdress = "";
|
||||
/// <summary>
|
||||
/// 查看相机列表
|
||||
/// </summary>
|
||||
@ -188,11 +199,25 @@ namespace HisenceYoloDetection
|
||||
/// <param name="e"></param>
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
//报警地址
|
||||
|
||||
|
||||
|
||||
string s1 = "ECO4060##Coton20℃##Rapide15mns";
|
||||
string s2 = "Eco4060##Coton20℃##Rapide15mns";
|
||||
if (_runHandleBefore == null)
|
||||
{
|
||||
_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);
|
||||
//string path2 = "D:\\Hisence\\SQLImages\\W80WXWJ060539V0WW80WX120293\\2\\W80WXWJ060539V0WW80WX120293result.jpg";
|
||||
@ -264,6 +289,8 @@ namespace HisenceYoloDetection
|
||||
|
||||
OnSpeedShow();//线程开启将速度显示在界面上
|
||||
OnPostionShow();//线程开启将位置显示在界面上
|
||||
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
|
||||
|
||||
//t = new System.Timers.Timer(10000);//实例化Timer类,设置间隔时间为10000毫秒;
|
||||
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件;
|
||||
//t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
|
||||
@ -273,6 +300,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
public void Execute(object source, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
t.Stop(); //先关闭定时器
|
||||
//melsecPLCTCPDriver.WriteInt("548", 1);
|
||||
//Thread.Sleep(1000);
|
||||
@ -520,6 +548,7 @@ namespace HisenceYoloDetection
|
||||
// tbFrameRate.Enabled = false;
|
||||
bnGetParam.Enabled = false;
|
||||
bnSetParam.Enabled = false;
|
||||
|
||||
}
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -549,6 +578,7 @@ namespace HisenceYoloDetection
|
||||
Bitmap NGbitmap = new Bitmap("NG.jpg");
|
||||
Mat OKMat = Cv2.ImRead("OK.jpg");
|
||||
Mat NGMat = Cv2.ImRead("OK.jpg");
|
||||
Mat whiteMat = Cv2.ImRead("white.jpg");
|
||||
/// <summary>
|
||||
/// 主线程调用
|
||||
/// </summary>
|
||||
@ -585,17 +615,17 @@ namespace HisenceYoloDetection
|
||||
//Scanner.OnClientDataReceived += OnDataReceived;
|
||||
//Scanner.btnSendMsg("LON\r");//发送开启指令
|
||||
//myLog("发送恩士扫码枪开启指令", DateTime.Now);
|
||||
|
||||
|
||||
//PLC使能开启
|
||||
melsecPLCTCPDriver.WriteInt("581", 0);//定位松开
|
||||
melsecPLCTCPDriver.WriteInt("504", 0);//定位松开
|
||||
melsecPLCTCPDriver.WriteInt("514", 0);//定位松开
|
||||
melsecPLCTCPDriver.WriteInt("524", 0);//定位松开
|
||||
melsecPLCTCPDriver.WriteInt("406", 60000); //写入手动速度
|
||||
melsecPLCTCPDriver.WriteInt("416", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("416", 10000);
|
||||
melsecPLCTCPDriver.WriteInt("426", 10000);
|
||||
melsecPLCTCPDriver.WriteInt("404", 100000); //写入定位速度
|
||||
melsecPLCTCPDriver.WriteInt("414", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("414", 10000);
|
||||
melsecPLCTCPDriver.WriteInt("424", 10000);
|
||||
|
||||
|
||||
@ -610,6 +640,7 @@ namespace HisenceYoloDetection
|
||||
Thread.Sleep(200);
|
||||
melsecPLCTCPDriver.WriteInt("580", 0);
|
||||
Thread.Sleep(200);
|
||||
melsecPLCTCPDriver.WriteInt("550", 0);
|
||||
while (true)
|
||||
{
|
||||
int IfXZeros = melsecPLCTCPDriver.ReadInt("102");
|
||||
@ -975,11 +1006,12 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
if (iNum1 >= 2)
|
||||
{
|
||||
|
||||
if (bBar)
|
||||
{
|
||||
_runHandleBefore.WaitOne();
|
||||
bBarTriger = true;//修改成相机拍照获取型号
|
||||
Cam2.SnapshotCount = 0;
|
||||
Cam2.Snapshot();
|
||||
|
||||
|
||||
xKNow = GetModeFromBar("VWJ070633V0WW80F0120356");//从数据库中查询到这个条码的四轴的值
|
||||
//xKNow = GetModeFromBar(m_sKEYENCEBar);//从数据库中查询到这个条码的四轴的值
|
||||
@ -1037,6 +1069,7 @@ namespace HisenceYoloDetection
|
||||
#endregion
|
||||
int YPos = 8715;
|
||||
int ZPos = 25000;
|
||||
bool StopM = false;//第一次用信号挡
|
||||
/// <summary>
|
||||
/// 监听洗衣机544是否触发后面对射传感器 相机
|
||||
/// </summary>
|
||||
@ -1079,13 +1112,21 @@ namespace HisenceYoloDetection
|
||||
else
|
||||
{
|
||||
iNum1 = 0;
|
||||
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
|
||||
}
|
||||
if (iNum1 >= 2)
|
||||
{
|
||||
//if (bBarTriger)
|
||||
{
|
||||
|
||||
#if true
|
||||
#if false
|
||||
if (!StopM)
|
||||
{
|
||||
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
|
||||
StopM = true;
|
||||
|
||||
}
|
||||
|
||||
myLog("第一次采集图像", DateTime.Now);
|
||||
//移动模组 读三次测距的地址 看是否往前移动
|
||||
MoveToP(5815, YPos, ZPos);
|
||||
@ -1106,7 +1147,7 @@ namespace HisenceYoloDetection
|
||||
double disreal = average * (-0.54054) + 1324.3232;
|
||||
//测距距离-标准距离=要移动的距离
|
||||
double dismove = disreal - 876;
|
||||
if (dismove > 0 && dismove < 4000)
|
||||
if (dismove > -4000 && dismove < 4000)
|
||||
{
|
||||
MoveToP(5815, YPos, ZPos + (int)(dismove));
|
||||
}
|
||||
@ -1114,19 +1155,22 @@ namespace HisenceYoloDetection
|
||||
// Thread.Sleep(500);
|
||||
Cam1.SnapshotCount = 0;
|
||||
Cam1.Snapshot();
|
||||
|
||||
|
||||
Cam2.SnapshotCount = 0;
|
||||
Cam2.Snapshot();
|
||||
myLog("第二次采集图像", DateTime.Now);
|
||||
|
||||
//if (xKNow != null)
|
||||
//{
|
||||
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
|
||||
//}
|
||||
//currentXP = 54964;
|
||||
//Thread.Sleep(2000);//删
|
||||
|
||||
MoveToP(51043, YPos, ZPos + (int)(dismove));
|
||||
Cam1.Snapshot();
|
||||
MoveToP(5815, YPos, ZPos);
|
||||
melsecPLCTCPDriver.WriteInt("550", 0);//方行
|
||||
//Thread.Sleep(300);//洗衣机可能过不去
|
||||
|
||||
//if (xKNow != null)
|
||||
//{
|
||||
// MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);
|
||||
@ -1168,7 +1212,7 @@ namespace HisenceYoloDetection
|
||||
// Thread.Sleep(500);
|
||||
Cam1.SnapshotCount = 0;
|
||||
Cam1.Snapshot();
|
||||
|
||||
|
||||
// Cam2.SnapshotCount = 0;
|
||||
//Cam2.Snapshot();
|
||||
IfCam2Triger = true;
|
||||
@ -1179,7 +1223,7 @@ namespace HisenceYoloDetection
|
||||
//}
|
||||
//currentXP = 54964;
|
||||
Thread.Sleep(2000);//删
|
||||
|
||||
|
||||
//MoveToP(51043, YPos, ZPos + (int)(dismove));
|
||||
Cam1.Snapshot();
|
||||
//MoveToP(5815, YPos, ZPos);
|
||||
@ -1257,8 +1301,8 @@ namespace HisenceYoloDetection
|
||||
{
|
||||
|
||||
|
||||
// Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\类型\\1\\202461817464661.jpg"); ;
|
||||
Cam1ImgOne = cameraMat;
|
||||
Cam1ImgOne = Cv2.ImRead("D:\\Hisence\\类型\\1\\001.jpg"); ;
|
||||
//Cam1ImgOne = cameraMat;
|
||||
IfCam1OneTriger = true;
|
||||
originMatShow.Image = cameraMat.ToBitmap();
|
||||
//pictureBox1.Image = cameraMat.ToBitmap();
|
||||
@ -1268,13 +1312,13 @@ namespace HisenceYoloDetection
|
||||
//第二次拍照
|
||||
if (SnapshotCount == 2)
|
||||
{
|
||||
//Mat mat = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
|
||||
//Cam1ImgTwo = mat;
|
||||
Cam1ImgTwo = cameraMat;
|
||||
|
||||
Cam1ImgTwo = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
|
||||
//Cam1ImgTwo = cameraMat;
|
||||
|
||||
IfCam1TwoTriger = true;
|
||||
originMatShow2.Image = cameraMat.ToBitmap();
|
||||
|
||||
_runHandleAfter.Set();
|
||||
}
|
||||
|
||||
|
||||
@ -1300,8 +1344,9 @@ namespace HisenceYoloDetection
|
||||
// Mat mat = Cv2.ImRead("F:\\海信洗衣机\\cam1\\2024517161641.jpg");
|
||||
Cam2ImgShowBar = cameraMat;
|
||||
IfCam2Triger = true;
|
||||
originMat2Show.Image = cameraMat.ToBitmap();
|
||||
|
||||
originMat2Show.Image = cameraMat.ToBitmap();
|
||||
//_runHandleAfter.Set();
|
||||
// CamShow2.ImaMAt = cameraMat;
|
||||
cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
|
||||
|
||||
@ -1309,18 +1354,21 @@ namespace HisenceYoloDetection
|
||||
public volatile int AllDsums = 0;
|
||||
public volatile int NGDsums = 0;
|
||||
public volatile int OKDsums = 0;
|
||||
public volatile int WUsums = 0;
|
||||
/// <summary>
|
||||
/// 开始识别
|
||||
/// </summary>
|
||||
public void ReadyDetect()
|
||||
{
|
||||
Task.Run((Action)(() =>
|
||||
_ = Task.Run((Action)(() =>
|
||||
{
|
||||
Thread.CurrentThread.Priority = ThreadPriority.Highest;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
//信号量阻塞 使其不在总数增加和闪烁
|
||||
_runHandleAfter.WaitOne();
|
||||
//相机2第一次拍照
|
||||
if (IfCam2Triger)
|
||||
{
|
||||
@ -1340,7 +1388,8 @@ namespace HisenceYoloDetection
|
||||
sw.WriteLine(IOcrBAr + "\n");
|
||||
sw.Flush();
|
||||
}
|
||||
IOcrBAr = "BatchW825UModelWNHEI74SAS";
|
||||
// IOcrBAr = "BatchW9659ModelWNHPI74SCPSDE";
|
||||
IOcrBAr = "W821PWMS27106WD2";
|
||||
//根据条码数据库比对
|
||||
xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
|
||||
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
|
||||
@ -1381,12 +1430,24 @@ namespace HisenceYoloDetection
|
||||
//从数据库中匹配完才可以进行模组移动
|
||||
//如果这次型号和上次的型号一样 就不用换识别模型ll
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//相机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_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
|
||||
AllDsums++;
|
||||
@ -1408,19 +1469,14 @@ namespace HisenceYoloDetection
|
||||
List<string> strMatListOne = new List<string>();
|
||||
List<string> strMatFuzzyListOne = new List<string>();
|
||||
Mat mResultCut = req.currentMat.Clone();
|
||||
Mat mCut = new Mat();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
|
||||
InsertSqlRunDataButton(ref keyValueResult, false, ref mCut, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
|
||||
sw.Stop();
|
||||
myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
|
||||
|
||||
if (mL.ResultMap != null)
|
||||
{
|
||||
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
|
||||
ResultMatShow.Image = mL.ResultMap;
|
||||
|
||||
}
|
||||
|
||||
//进行推理
|
||||
MLRequest req2 = new MLRequest();
|
||||
req2.currentMat = Cam1ImgTwo;
|
||||
@ -1432,18 +1488,18 @@ namespace HisenceYoloDetection
|
||||
req2.iouThreshold = 0.4f;//检测IOU
|
||||
req2.out_node_name = "output";
|
||||
MLResult mL2 = simboObjectDetection.RunInferenceFixed(req2);
|
||||
List<string> strMatListTwo = new List<string>();
|
||||
List<string> strMatFuzzyListTwo = new List<string>();
|
||||
Mat mResultCut2 = req2.currentMat.Clone();
|
||||
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
|
||||
InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
|
||||
|
||||
if (mL2.ResultMap != null)
|
||||
{
|
||||
mL2.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "2result.jpg");
|
||||
ResultMatShow2.Image = mL2.ResultMap;
|
||||
}
|
||||
|
||||
List<string> strMatListTwo = new List<string>();
|
||||
List<string> strMatFuzzyListTwo = new List<string>();
|
||||
Mat mResultCut2 = req2.currentMat.Clone();
|
||||
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
|
||||
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
|
||||
#region 先执行定位比对
|
||||
//执行定位数组块
|
||||
string[] listLabels = xKNow.Detect.Split(",");
|
||||
|
||||
@ -1466,34 +1522,49 @@ namespace HisenceYoloDetection
|
||||
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 = 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)
|
||||
{
|
||||
OKDsums++;
|
||||
@ -1509,14 +1580,39 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
NGDsums++;
|
||||
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
|
||||
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
|
||||
myLog("匹配失败", DateTime.Now);
|
||||
//界面显示
|
||||
// InsertXK_HisenceWordMatchData(xK_MatchDet, false);
|
||||
this.Invoke(new Action(() =>
|
||||
//加上人为判断是否是NG洗衣机
|
||||
DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
||||
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)
|
||||
{
|
||||
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -1605,7 +1701,7 @@ namespace HisenceYoloDetection
|
||||
{
|
||||
m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data);
|
||||
// myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now);
|
||||
|
||||
_runHandleBefore.Set();
|
||||
bBar = true;
|
||||
}
|
||||
|
||||
@ -1785,17 +1881,31 @@ namespace HisenceYoloDetection
|
||||
|
||||
private void StartDecBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
/*
|
||||
string path22 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628924614_Rect.png";
|
||||
Mat pathmat2 = Cv2.ImRead(path22);
|
||||
string path222 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628923102_Rect.png";
|
||||
Rect rect1 = new Rect(1929, 745, 396, 377);
|
||||
Rect rect = new Rect(368, 53, 396, 377);
|
||||
|
||||
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
|
||||
|
||||
string path = "D:\\Hisence\\Test1\\1.png";
|
||||
Mat pathmat =Cv2.ImRead(path);
|
||||
string path2 = "D:\\Hisence\\Test1\\2.png";
|
||||
|
||||
Rect rect2 = new Rect(0, 0, 0, 0);
|
||||
|
||||
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
|
||||
|
||||
*/
|
||||
//OnGetBar();
|
||||
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯
|
||||
TriggerCameral2();
|
||||
ReadyDetect();
|
||||
myLog("开启流程成功", DateTime.Now);
|
||||
}
|
||||
|
||||
private void InsertSqlBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void RefeshData_Click(object sender, EventArgs e)
|
||||
{
|
||||
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
|
||||
@ -1849,7 +1959,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
//按下状态标识
|
||||
private bool m_btnState;
|
||||
|
||||
|
||||
|
||||
private void YZerorbx_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -2188,9 +2298,9 @@ namespace HisenceYoloDetection
|
||||
List<string> strMatListOne = new List<string>();
|
||||
List<string> strMatFuzzyListOne = new List<string>();
|
||||
Mat mResultCut = CamOneI.currentMat.Clone();
|
||||
Mat mCut = new Mat();
|
||||
//Mat mCut = new Mat();
|
||||
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
|
||||
InsertSqlRunDataButton(ref keyValueResult, true, ref mCut, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
|
||||
InsertSqlRunDataButton(ref keyValueResult, true, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
|
||||
|
||||
|
||||
|
||||
@ -2594,42 +2704,42 @@ namespace HisenceYoloDetection
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
DefetShow1.ImaMAt = detectionImage;
|
||||
canvas1.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
DefetShow2.ImaMAt = detectionImage;
|
||||
canvas2.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
DefetShow3.ImaMAt = detectionImage;
|
||||
canvas3.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
DefetShow4.ImaMAt = detectionImage;
|
||||
canvas4.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
DefetShow5.ImaMAt = detectionImage;
|
||||
canvas5.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
// DefetShow6.ImaMAt = detectionImage;
|
||||
canvas6.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
// DefetShow7.ImaMAt = detectionImage;
|
||||
// canvas7.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
// DefetShow8.ImaMAt = detectionImage;
|
||||
//DefetShow8.ImaMAt = detectionImage;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -2654,12 +2764,18 @@ namespace HisenceYoloDetection
|
||||
/// <param name="strMatList">返回的定位框的结果</param>
|
||||
/// <param name="strMatRefList"></param>
|
||||
/// <param name="IOcrModel"></param>
|
||||
public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat CutMat, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
|
||||
public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
|
||||
{
|
||||
#if true
|
||||
//try
|
||||
//{
|
||||
|
||||
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();
|
||||
Rect areaBlack = new Rect();
|
||||
//旋钮的位置
|
||||
@ -2673,9 +2789,9 @@ namespace HisenceYoloDetection
|
||||
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();
|
||||
int rectsx = cam1TwoML.ResultDetails[i].Rect.X;
|
||||
@ -2684,16 +2800,16 @@ namespace HisenceYoloDetection
|
||||
int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height;
|
||||
|
||||
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
|
||||
if(keyValueResult.Keys.Contains(blockIndex))
|
||||
if (keyValueResult.Keys.Contains(blockIndex))
|
||||
{
|
||||
int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex);
|
||||
|
||||
int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X;
|
||||
if(rectsx> rectsxof)
|
||||
if (rectsx > rectsxof)
|
||||
{
|
||||
blockIndex = "3";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Rect area2 = new Rect(0, 0, 0, 0);
|
||||
Mat matCut = new Mat();
|
||||
@ -2766,6 +2882,7 @@ namespace HisenceYoloDetection
|
||||
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
|
||||
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
|
||||
Mat matCut = new Mat(mResultCuti, area);
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
//OCR识别裁剪图片
|
||||
@ -2847,6 +2964,7 @@ namespace HisenceYoloDetection
|
||||
string TextWoidStr = OcrFuzzyTextInsert.Join("##"); //实际的检测字
|
||||
string SQLStr = "";//日志显示数据库的关键字
|
||||
bool juanjiMatch = false;
|
||||
string filenameone = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
switch (blockIndex)
|
||||
{
|
||||
case "1"://完全匹配 重量信息
|
||||
@ -2854,19 +2972,31 @@ namespace HisenceYoloDetection
|
||||
xK_HisenceWord.OneblockPath = CutSavePath;
|
||||
xK_HisenceWord.OneblockMainWord = MainWoidStr;
|
||||
xK_HisenceWord.OneblockText = TextWoidStr;
|
||||
SQLStr = SQlxK_HisenceWord.OneblockMainWord;
|
||||
SQLStr = SQlxK_HisenceWord.OneblockText;
|
||||
string SQLStr2 = SQlxK_HisenceWord.OneblockMainWord;
|
||||
|
||||
if (!saveimage)
|
||||
{
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr);
|
||||
if (!OneIF)
|
||||
bool ssD = ManagerModelHelper.StrMatch(SQLStr, xK_HisenceWord.OneblockText);
|
||||
Console.Write(SQLStr);
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.OneblockMainWord, SQLStr2);
|
||||
if (!OneIF1 || !ssD)
|
||||
{
|
||||
OneIF = false;
|
||||
//显示错误的板
|
||||
DisplayResult(mLcut);
|
||||
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 1);
|
||||
|
||||
string Path_1 = Path.Combine("D:\\Hisence\\Test\\1\\ng", filenameone + "_res.png");
|
||||
Cv2.ImWrite(Path_1, mLcut.ResultMap.ToMat());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 1);
|
||||
string Path_2 = Path.Combine("D:\\Hisence\\Test\\1\\ok", filenameone + "_res.png");
|
||||
Cv2.ImWrite(Path_2, OKMat);
|
||||
}
|
||||
|
||||
}
|
||||
@ -2881,7 +3011,7 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
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;
|
||||
//第二快 卷积匹配
|
||||
string PathSql = SQlxK_HisenceWord.TwoblockPath;
|
||||
@ -2890,7 +3020,7 @@ namespace HisenceYoloDetection
|
||||
Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect);
|
||||
Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect);
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rectsql, rectDet, (bool)SQlxK_HisenceWord.TwoIFWhile, "D://Hisence//Test");
|
||||
// juanjiMatch = true;
|
||||
// juanjiMatch = true;
|
||||
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
@ -2916,16 +3046,26 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.ThreeblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.ThreeblockMainWord, SQlxK_HisenceWord.ThreeblockMainWord);
|
||||
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.ThreeblockPath;
|
||||
|
||||
juanjiMatch = CheckDiffSciHelper1.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test1");
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = true;//待修改6.28
|
||||
/*
|
||||
DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 3);
|
||||
*/
|
||||
Defet_OnDetectionDone(OKMat, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 3);
|
||||
}
|
||||
|
||||
@ -2940,9 +3080,15 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.FourblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
|
||||
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.FourblockPath;
|
||||
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = false;
|
||||
DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
@ -2950,6 +3096,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 4);
|
||||
}
|
||||
|
||||
@ -2964,9 +3111,14 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.FiveblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.FiveblockMainWord;
|
||||
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = false;
|
||||
DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
@ -2974,6 +3126,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 5);
|
||||
}
|
||||
}
|
||||
@ -2987,9 +3140,16 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.SixblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
|
||||
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.SixblockPath;
|
||||
//第六块卷积设置一直为true
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
|
||||
juanjiMatch = true;
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = false;
|
||||
// DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
@ -2997,6 +3157,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 6);
|
||||
}
|
||||
|
||||
@ -3011,9 +3172,14 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.SevenblockPath;
|
||||
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = false;
|
||||
//DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
@ -3021,6 +3187,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 7);
|
||||
}
|
||||
}
|
||||
@ -3034,9 +3201,14 @@ namespace HisenceYoloDetection
|
||||
if (!saveimage)
|
||||
{
|
||||
SQLStr = SQlxK_HisenceWord.EightblockMainWord;
|
||||
OneIF = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord);
|
||||
if (!OneIF)
|
||||
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.EightblockMainWord, SQlxK_HisenceWord.EightblockMainWord);
|
||||
Rect rect = new Rect(0, 0, 0, 0);
|
||||
string PathSql = SQlxK_HisenceWord.EightblockPath;
|
||||
|
||||
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
|
||||
if (!OneIF1 || !juanjiMatch)
|
||||
{
|
||||
OneIF = false;
|
||||
// DisplayResult(mLcut);
|
||||
//显示错误的板
|
||||
// mLcut.ResultMap;
|
||||
@ -3044,20 +3216,20 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
else
|
||||
{
|
||||
OneIF = true;
|
||||
Defet_OnDetectionDone(OKMat, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
if (blockIndex == "2")
|
||||
{
|
||||
sw.WriteLine("卷积匹配" + juanjiMatch);
|
||||
}
|
||||
|
||||
sw.WriteLine("块" + blockIndex + "卷积匹配" + juanjiMatch);
|
||||
sw.WriteLine("块" + blockIndex + "数据库" + SQLStr + "关键字" + MainWoidStr + "结果" + OneIF + "\n");
|
||||
sw.WriteLine("块" + blockIndex + " 所有字 " + TextWoidStr + "\n");
|
||||
|
||||
@ -3109,5 +3281,20 @@ namespace HisenceYoloDetection
|
||||
myLog("X轴停止归零", DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
private void handStopBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
melsecPLCTCPDriver.WriteInt("550", 1);
|
||||
}
|
||||
|
||||
private void HandRuningBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
melsecPLCTCPDriver.WriteInt("550", 0);
|
||||
}
|
||||
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
melsecPLCTCPDriver.WriteInt("550", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@
|
||||
<value>733, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>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">
|
||||
|
@ -189,7 +189,7 @@ namespace HisenceYoloDetection
|
||||
// 计算相似度(相似度等于1减去标准化的Levenshtein距离)
|
||||
double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length));
|
||||
bool areEqual = false;
|
||||
if (similarity < 0.5)
|
||||
if (similarity < 0.9)
|
||||
{
|
||||
areEqual = false;
|
||||
}
|
||||
@ -227,10 +227,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 +252,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 +280,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);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ using static OpenCvSharp.FileStorage;
|
||||
|
||||
|
||||
|
||||
public class MelsecPLCTCPDriver
|
||||
public class MelsecPLCTCPDriver1
|
||||
{
|
||||
private MelsecMcNet melsecMc = new MelsecMcNet();
|
||||
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();
|
||||
|
@ -12,7 +12,7 @@ using static OpenCvSharp.FileStorage;
|
||||
|
||||
|
||||
|
||||
public class MelsecPLCTCPDriver1
|
||||
public class MelsecPLCTCPDriver
|
||||
{
|
||||
// private MelsecMcNet melsecMc = new MelsecMcNet();
|
||||
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();
|
||||
|
@ -399,6 +399,7 @@ namespace XKRS.UI
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 画矩形
|
||||
GPathList.ForEach(path =>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user