Compare commits

...

7 Commits

Author SHA1 Message Date
48e6945bd6 修改卷积 2024-06-28 09:15:00 +08:00
3f9d951e80 修改 2024-06-27 18:02:33 +08:00
00f4b9c95d 修改所有区域卷积 2024-06-27 17:54:35 +08:00
0ed659e482 no message 2024-06-27 16:51:09 +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
5 changed files with 227 additions and 161 deletions

View File

@ -1,4 +1,5 @@
using OpenCvSharp;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,7 +15,6 @@ namespace HisenceYoloDetection
{
public static class CheckDiffSciHelper
{
/// <summary>
///
/// </summary>
@ -22,7 +22,7 @@ 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);
@ -31,31 +31,31 @@ namespace HisenceYoloDetection
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,9 +68,7 @@ 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;
@ -96,15 +94,15 @@ 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();
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr1.png");
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
// 保存结果
Cv2.ImWrite(savePath4, thr1);
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png");
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
// 保存结果
Cv2.ImWrite(savePath3, thr2);
// 创建卷积核
@ -160,7 +158,7 @@ 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)
@ -169,27 +167,28 @@ namespace HisenceYoloDetection
{
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;
isMatch = false;
}
}
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_Rect.png");
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath2, img2);
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_diff.png");
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png");
// 保存结果
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
Cv2.ImWrite(savePath, blackhatImg);
return isMatch;
}
public static Rect strChangeRect(string strrect)
{
if (!string.IsNullOrEmpty(strrect))

View File

@ -31,11 +31,13 @@
components = new System.ComponentModel.Container();
OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat6 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat7 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat8 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat9 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
tabPage2 = new TabPage();
panel1 = new Panel();
@ -128,7 +130,6 @@
panel5 = new Panel();
DefetShow5 = new XKRS.UI.Canvas();
panel8 = new Panel();
RefeshData = new Button();
= new Label();
OKOrNGShow = new PictureBox();
OKDNum = new TextBox();
@ -137,7 +138,6 @@
label19 = new Label();
AllDSum = new TextBox();
label18 = new Label();
InsertSqlBtn = new Button();
StartDecBtn = new Button();
ScanDevList = new Button();
DevNameCombo = new ComboBox();
@ -198,6 +198,8 @@
richTextBox1 = new RichTextBox();
contextMenuStrip1 = new ContextMenuStrip(components);
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
DefetShow6 = new XKRS.UI.Canvas();
DefetShow7 = new XKRS.UI.Canvas();
tabPage2.SuspendLayout();
panel1.SuspendLayout();
groupBox5.SuspendLayout();
@ -1129,8 +1131,10 @@
//
// panel5
//
panel5.Controls.Add(DefetShow5);
panel5.Controls.Add(DefetShow7);
panel5.Controls.Add(DefetShow6);
panel5.Controls.Add(panel8);
panel5.Controls.Add(DefetShow2);
panel5.Controls.Add(panel6);
panel5.Dock = DockStyle.Top;
panel5.Location = new Point(0, 0);
@ -1143,15 +1147,15 @@
DefetShow5.AllowSelectDefect = true;
DefetShow5.BrushColor = null;
DefetShow5.ImagePath = "";
mat3.IsEnabledDispose = true;
DefetShow5.ImaMAt = mat3;
mat6.IsEnabledDispose = true;
DefetShow5.ImaMAt = mat6;
DefetShow5.ImgData = null;
DefetShow5.Location = new Point(853, 464);
DefetShow5.Location = new Point(537, 460);
DefetShow5.MoveStep = 5F;
DefetShow5.Name = "DefetShow5";
DefetShow5.Route = 0D;
DefetShow5.Scale = 1D;
DefetShow5.Size = new Size(254, 196);
DefetShow5.Size = new Size(209, 196);
DefetShow5.TabIndex = 10;
DefetShow5.WholeScale = 0F;
DefetShow5.XMove = 0F;
@ -1161,7 +1165,6 @@
//
// panel8
//
panel8.Controls.Add(RefeshData);
panel8.Controls.Add();
panel8.Controls.Add(OKOrNGShow);
panel8.Controls.Add(OKDNum);
@ -1170,31 +1173,20 @@
panel8.Controls.Add(label19);
panel8.Controls.Add(AllDSum);
panel8.Controls.Add(label18);
panel8.Controls.Add(InsertSqlBtn);
panel8.Controls.Add(StartDecBtn);
panel8.Controls.Add(ScanDevList);
panel8.Controls.Add(DevNameCombo);
panel8.Controls.Add(InitMachine);
panel8.Location = new Point(853, 0);
panel8.Name = "panel8";
panel8.Size = new Size(440, 458);
panel8.Size = new Size(440, 244);
panel8.TabIndex = 2;
panel8.Paint += panel8_Paint;
//
// RefeshData
//
RefeshData.Location = new Point(24, 340);
RefeshData.Name = "RefeshData";
RefeshData.Size = new Size(94, 43);
RefeshData.TabIndex = 13;
RefeshData.Text = "刷新";
RefeshData.UseVisualStyleBackColor = true;
RefeshData.Click += RefeshData_Click;
//
// 实时显示
//
.AutoSize = true;
.Location = new Point(326, 175);
.Location = new Point(332, 26);
.Name = "实时显示";
.Size = new Size(56, 17);
.TabIndex = 12;
@ -1202,7 +1194,7 @@
//
// OKOrNGShow
//
OKOrNGShow.Location = new Point(254, 204);
OKOrNGShow.Location = new Point(254, 60);
OKOrNGShow.Name = "OKOrNGShow";
OKOrNGShow.Size = new Size(183, 179);
OKOrNGShow.SizeMode = PictureBoxSizeMode.CenterImage;
@ -1211,7 +1203,7 @@
//
// OKDNum
//
OKDNum.Location = new Point(125, 296);
OKDNum.Location = new Point(132, 207);
OKDNum.Name = "OKDNum";
OKDNum.ReadOnly = true;
OKDNum.Size = new Size(100, 23);
@ -1220,7 +1212,7 @@
// label20
//
label20.AutoSize = true;
label20.Location = new Point(49, 300);
label20.Location = new Point(56, 211);
label20.Name = "label20";
label20.Size = new Size(50, 17);
label20.TabIndex = 9;
@ -1228,7 +1220,7 @@
//
// NGDNum
//
NGDNum.Location = new Point(125, 249);
NGDNum.Location = new Point(132, 160);
NGDNum.Name = "NGDNum";
NGDNum.ReadOnly = true;
NGDNum.Size = new Size(100, 23);
@ -1237,7 +1229,7 @@
// label19
//
label19.AutoSize = true;
label19.Location = new Point(49, 253);
label19.Location = new Point(56, 164);
label19.Name = "label19";
label19.Size = new Size(51, 17);
label19.TabIndex = 7;
@ -1245,7 +1237,7 @@
//
// AllDSum
//
AllDSum.Location = new Point(125, 204);
AllDSum.Location = new Point(132, 115);
AllDSum.Name = "AllDSum";
AllDSum.ReadOnly = true;
AllDSum.Size = new Size(100, 23);
@ -1254,26 +1246,15 @@
// label18
//
label18.AutoSize = true;
label18.Location = new Point(49, 208);
label18.Location = new Point(56, 119);
label18.Name = "label18";
label18.Size = new Size(44, 17);
label18.TabIndex = 5;
label18.Text = "总个数";
//
// InsertSqlBtn
//
InsertSqlBtn.Location = new Point(54, 56);
InsertSqlBtn.Name = "InsertSqlBtn";
InsertSqlBtn.Size = new Size(92, 48);
InsertSqlBtn.TabIndex = 4;
InsertSqlBtn.Text = "型号录入";
InsertSqlBtn.UseVisualStyleBackColor = true;
InsertSqlBtn.Visible = false;
InsertSqlBtn.Click += InsertSqlBtn_Click;
//
// StartDecBtn
//
StartDecBtn.Location = new Point(160, 127);
StartDecBtn.Location = new Point(131, 60);
StartDecBtn.Name = "StartDecBtn";
StartDecBtn.Size = new Size(94, 43);
StartDecBtn.TabIndex = 3;
@ -1283,7 +1264,7 @@
//
// ScanDevList
//
ScanDevList.Location = new Point(272, 25);
ScanDevList.Location = new Point(231, 23);
ScanDevList.Name = "ScanDevList";
ScanDevList.Size = new Size(75, 23);
ScanDevList.TabIndex = 2;
@ -1294,14 +1275,14 @@
// DevNameCombo
//
DevNameCombo.FormattingEnabled = true;
DevNameCombo.Location = new Point(54, 25);
DevNameCombo.Location = new Point(25, 23);
DevNameCombo.Name = "DevNameCombo";
DevNameCombo.Size = new Size(200, 25);
DevNameCombo.TabIndex = 1;
//
// InitMachine
//
InitMachine.Location = new Point(54, 127);
InitMachine.Location = new Point(24, 60);
InitMachine.Name = "InitMachine";
InitMachine.Size = new Size(94, 43);
InitMachine.TabIndex = 0;
@ -1320,9 +1301,9 @@
// groupBox2
//
groupBox2.AutoSize = true;
groupBox2.Controls.Add(DefetShow5);
groupBox2.Controls.Add(DefetShow4);
groupBox2.Controls.Add(DefetShow3);
groupBox2.Controls.Add(DefetShow2);
groupBox2.Controls.Add(originMat2Show);
groupBox2.Controls.Add(DefetShow1);
groupBox2.Controls.Add(ResultMatShow2);
@ -1342,15 +1323,15 @@
DefetShow4.AllowSelectDefect = true;
DefetShow4.BrushColor = null;
DefetShow4.ImagePath = "";
mat4.IsEnabledDispose = true;
DefetShow4.ImaMAt = mat4;
mat7.IsEnabledDispose = true;
DefetShow4.ImaMAt = mat7;
DefetShow4.ImgData = null;
DefetShow4.Location = new Point(574, 460);
DefetShow4.Location = new Point(297, 460);
DefetShow4.MoveStep = 5F;
DefetShow4.Name = "DefetShow4";
DefetShow4.Route = 0D;
DefetShow4.Scale = 1D;
DefetShow4.Size = new Size(265, 196);
DefetShow4.Size = new Size(220, 196);
DefetShow4.TabIndex = 11;
DefetShow4.WholeScale = 0F;
DefetShow4.XMove = 0F;
@ -1363,15 +1344,15 @@
DefetShow3.AllowSelectDefect = true;
DefetShow3.BrushColor = null;
DefetShow3.ImagePath = "";
mat5.IsEnabledDispose = true;
DefetShow3.ImaMAt = mat5;
mat8.IsEnabledDispose = true;
DefetShow3.ImaMAt = mat8;
DefetShow3.ImgData = null;
DefetShow3.Location = new Point(303, 460);
DefetShow3.Location = new Point(6, 460);
DefetShow3.MoveStep = 5F;
DefetShow3.Name = "DefetShow3";
DefetShow3.Route = 0D;
DefetShow3.Scale = 1D;
DefetShow3.Size = new Size(265, 196);
DefetShow3.Size = new Size(285, 196);
DefetShow3.TabIndex = 10;
DefetShow3.WholeScale = 0F;
DefetShow3.XMove = 0F;
@ -1384,10 +1365,10 @@
DefetShow2.AllowSelectDefect = true;
DefetShow2.BrushColor = null;
DefetShow2.ImagePath = "";
mat6.IsEnabledDispose = true;
DefetShow2.ImaMAt = mat6;
mat5.IsEnabledDispose = true;
DefetShow2.ImaMAt = mat5;
DefetShow2.ImgData = null;
DefetShow2.Location = new Point(6, 460);
DefetShow2.Location = new Point(850, 249);
DefetShow2.MoveStep = 5F;
DefetShow2.Name = "DefetShow2";
DefetShow2.Route = 0D;
@ -1414,15 +1395,15 @@
DefetShow1.AllowSelectDefect = true;
DefetShow1.BrushColor = null;
DefetShow1.ImagePath = "";
mat7.IsEnabledDispose = true;
DefetShow1.ImaMAt = mat7;
mat9.IsEnabledDispose = true;
DefetShow1.ImaMAt = mat9;
DefetShow1.ImgData = null;
DefetShow1.Location = new Point(574, 245);
DefetShow1.MoveStep = 5F;
DefetShow1.Name = "DefetShow1";
DefetShow1.Route = 0D;
DefetShow1.Scale = 1D;
DefetShow1.Size = new Size(262, 209);
DefetShow1.Size = new Size(254, 209);
DefetShow1.TabIndex = 7;
DefetShow1.WholeScale = 0F;
DefetShow1.XMove = 0F;
@ -1836,6 +1817,48 @@
contextMenuStrip1.Name = "contextMenuStrip1";
contextMenuStrip1.Size = new Size(61, 4);
//
// DefetShow6
//
DefetShow6.AllowSelectDefect = true;
DefetShow6.BrushColor = null;
DefetShow6.ImagePath = "";
mat4.IsEnabledDispose = true;
DefetShow6.ImaMAt = mat4;
DefetShow6.ImgData = null;
DefetShow6.Location = new Point(751, 464);
DefetShow6.MoveStep = 5F;
DefetShow6.Name = "DefetShow6";
DefetShow6.Route = 0D;
DefetShow6.Scale = 1D;
DefetShow6.Size = new Size(209, 196);
DefetShow6.TabIndex = 11;
DefetShow6.WholeScale = 0F;
DefetShow6.XMove = 0F;
DefetShow6.XScale = 0F;
DefetShow6.YMove = 0F;
DefetShow6.YScale = 0F;
//
// DefetShow7
//
DefetShow7.AllowSelectDefect = true;
DefetShow7.BrushColor = null;
DefetShow7.ImagePath = "";
mat3.IsEnabledDispose = true;
DefetShow7.ImaMAt = mat3;
DefetShow7.ImgData = null;
DefetShow7.Location = new Point(1021, 464);
DefetShow7.MoveStep = 5F;
DefetShow7.Name = "DefetShow7";
DefetShow7.Route = 0D;
DefetShow7.Scale = 1D;
DefetShow7.Size = new Size(209, 196);
DefetShow7.TabIndex = 12;
DefetShow7.WholeScale = 0F;
DefetShow7.XMove = 0F;
DefetShow7.XScale = 0F;
DefetShow7.YMove = 0F;
DefetShow7.YScale = 0F;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 17F);
@ -1957,7 +1980,6 @@
private Label label15;
private Button StartDecBtn;
private ContextMenuStrip contextMenuStrip1;
private Button InsertSqlBtn;
private PictureBox ResultMatShow2;
private PictureBox originMatShow2;
private TextBox OKDNum;
@ -1968,7 +1990,6 @@
private Label label18;
private Label ;
private PictureBox OKOrNGShow;
private Button RefeshData;
private GroupBox groupBox3;
private Button SnapshotCam2;
private Button button3;
@ -2046,5 +2067,7 @@
private XKRS.UI.Canvas DefetShow3;
private XKRS.UI.Canvas DefetShow2;
private PictureBox originMat2Show;
private XKRS.UI.Canvas DefetShow7;
private XKRS.UI.Canvas DefetShow6;
}
}

View File

@ -5,6 +5,7 @@ using OpenCvSharp;
using OpenCvSharp.Dnn;
using OpenCvSharp.Extensions;
using OpenCvSharp.XFeatures2D;
using Sunny.UI;
using System;
using System.ComponentModel;
using System.Data;
@ -189,15 +190,16 @@ namespace HisenceYoloDetection
private void MainForm_Load(object sender, EventArgs e)
{
string s1 = "ECO4060##Coton20¡æ##Rapide15mns";
string s2 = "Eco4060##Coton20¡æ##Rapide15mns";
string s1 = "0##Ec04060##20℃##Rapide15mns";
string s2 = "ECO4060##20°C##Rapide15mns";
bool st = ManagerModelHelper.StrMatch2(s1, s2);
//Rect rect = new Rect(0, 0, 0, 0);
//string path2 = "D:\\Hisence\\SQLImages\\W80WXWJ060539V0WW80WX120293\\2\\W80WXWJ060539V0WW80WX120293result.jpg";
//Mat cameraMat = Cv2.ImRead(path2);
//bool ifg = CheckDiffSciHelper.CheckDiffSci(path2, cameraMat, rect, rect, false, "D://Hisence//Test");
Rect rect = new Rect(0, 0, 0, 0);
string path2 = "D:\\Hisence\\SQLImages\\LR1006G4SILVERWJ060480U0SW901N120105\\4\\LR1006G4SILVERWJ060480U0SW901N120105result.jpg";
string path23 = "D:\\Hisence\\SQLImages\\LR1006G4SILVERWJ060480U0SW901N120105\\4\\L1.jpg";
Mat cameraMat = Cv2.ImRead(path23);
bool ifg = CheckDiffSciHelper.CheckDiffSci(path2, cameraMat, rect, rect, false, "D://Hisence//Test");
string vBarPath = "D:\\Hisence\\类型\\Lp\\202452414231.jpg";
string vCam1OnePath = "D:\\Hisence\\类型\\Lp\\001.jpg";
@ -549,6 +551,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>
@ -1168,7 +1171,7 @@ namespace HisenceYoloDetection
// Thread.Sleep(500);
Cam1.SnapshotCount = 0;
Cam1.Snapshot();
// Cam2.SnapshotCount = 0;
//Cam2.Snapshot();
IfCam2Triger = true;
@ -1179,7 +1182,7 @@ namespace HisenceYoloDetection
//}
//currentXP = 54964;
Thread.Sleep(2000);//删
//MoveToP(51043, YPos, ZPos + (int)(dismove));
Cam1.Snapshot();
//MoveToP(5815, YPos, ZPos);
@ -1257,8 +1260,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,9 +1271,9 @@ namespace HisenceYoloDetection
//第二次拍照
if (SnapshotCount == 2)
{
//Mat mat = Cv2.ImRead("D:\\Hisence\\ÀàÐÍ\\1\\002.jpg");
//Cam1ImgTwo = mat;
Cam1ImgTwo = cameraMat;
// Mat mat = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
// Cam1ImgTwo = mat;
Cam1ImgTwo = cameraMat;
IfCam1TwoTriger = true;
originMatShow2.Image = cameraMat.ToBitmap();
@ -1314,7 +1317,7 @@ namespace HisenceYoloDetection
/// </summary>
public void ReadyDetect()
{
Task.Run((Action)(() =>
_ = Task.Run((Action)(() =>
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (true)
@ -1340,7 +1343,7 @@ namespace HisenceYoloDetection
sw.WriteLine(IOcrBAr + "\n");
sw.Flush();
}
IOcrBAr = "BatchW825UModelWNHEI74SAS";
IOcrBAr = "W821PWMS27106WD2";
//根据条码数据库比对
xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
@ -1381,12 +1384,22 @@ namespace HisenceYoloDetection
//从数据库中匹配完才可以进行模组移动
//如果这次型号和上次的型号一样 就不用换识别模型ll
}
//相机1第二次拍照
if (IfCam1TwoTriger && bBarTriger)
{
//初始化板
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++;
@ -1466,29 +1479,27 @@ namespace HisenceYoloDetection
detstr += RealLabels[i];
}
}
//排序比对块
HashSet<string> set1 = new HashSet<string>(listLabels);
HashSet<string> set2 = new HashSet<string>(RealLabels);
bool MatchStr = set1.SetEquals(set2);
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;
}
});
// int sqlblocksum=
IfCam1TwoTriger = false;
bBarTriger = false;
@ -1791,11 +1802,6 @@ namespace HisenceYoloDetection
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 +1855,7 @@ namespace HisenceYoloDetection
}
//按下状态标识
private bool m_btnState;
private void YZerorbx_Click(object sender, EventArgs e)
{
@ -2619,17 +2625,17 @@ namespace HisenceYoloDetection
break;
case 6:
{
// DefetShow6.ImaMAt = detectionImage;
DefetShow6.ImaMAt = detectionImage;
}
break;
case 7:
{
// DefetShow7.ImaMAt = detectionImage;
DefetShow7.ImaMAt = detectionImage;
}
break;
case 8:
{
// DefetShow8.ImaMAt = detectionImage;
//DefetShow8.ImaMAt = detectionImage;
}
break;
@ -2659,7 +2665,13 @@ namespace HisenceYoloDetection
#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 +2685,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 +2696,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();
@ -2881,7 +2893,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 +2902,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,8 +2928,13 @@ 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 = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
{
DisplayResult(mLcut);
//显示错误的板
@ -2940,8 +2957,13 @@ 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)
{
DisplayResult(mLcut);
//显示错误的板
@ -2964,8 +2986,12 @@ 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)
{
DisplayResult(mLcut);
//显示错误的板
@ -2987,8 +3013,14 @@ 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;
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
if (!OneIF1 || !juanjiMatch)
if (!OneIF)
{
// DisplayResult(mLcut);
//显示错误的板
@ -3011,8 +3043,12 @@ 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)
{
//DisplayResult(mLcut);
//显示错误的板
@ -3034,8 +3070,12 @@ 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)
{
// DisplayResult(mLcut);
//显示错误的板
@ -3050,14 +3090,15 @@ namespace HisenceYoloDetection
}
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");

View File

@ -142,7 +142,7 @@
<value>733, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>31</value>
<value>34</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

@ -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);
}