修改关闭检测

This commit is contained in:
YZJ 2024-07-22 16:50:01 +08:00
parent f1a9e75917
commit 267332bad5
4 changed files with 701 additions and 356 deletions

View File

@ -1,4 +1,5 @@
using OpenCvSharp;
using OpenCvSharp.Flann;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
@ -10,7 +11,10 @@ using static System.Net.Mime.MediaTypeNames;
using Point = OpenCvSharp.Point;
using Size = OpenCvSharp.Size;
using OpenCvSharp;
using OpenCvSharp.Features2D;
using OpenCvSharp.Flann;
using System.Drawing;
namespace HisenceYoloDetection
{
@ -57,6 +61,9 @@ namespace HisenceYoloDetection
return false;
}
// Cv2.Resize(img2, img2, new Size(550, 270));
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();
@ -73,9 +80,9 @@ namespace HisenceYoloDetection
//Rect area2 = new Rect(148,30,229,222);
sqlrect.Width += 20;
sqlrect.Height += 60;
sqlrect.Height+= 100;
detrect.Width += 20;
detrect.Height += 60;
detrect.Height+=100;
Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord)
@ -100,14 +107,14 @@ namespace HisenceYoloDetection
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");
//// 保存结果
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));
@ -128,12 +135,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);
@ -253,12 +260,14 @@ namespace HisenceYoloDetection
{
// 读取和处理第一张图片
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));
img1 = RemoveBorders(img1);
Mat gimg1 = new Mat();
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
Mat thr1 = new Mat();
@ -283,6 +292,7 @@ namespace HisenceYoloDetection
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();
@ -338,7 +348,7 @@ namespace HisenceYoloDetection
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
filter1.Row(7).SetTo(new Scalar(0.025));
filter1.Row(7).SetTo(new Scalar(0.025));
filter1.Col(7).SetTo(new Scalar(0.025));
@ -388,8 +398,8 @@ namespace HisenceYoloDetection
Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 9, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 9, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG, devIMG, 8, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 8, 255, ThresholdTypes.Binary);
// 结合差异
Mat sumIMG = new Mat();
@ -433,7 +443,100 @@ namespace HisenceYoloDetection
Cv2.ImWrite(savePath, blackhatImg);
return isMatch;
}
}
}
}
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;
}
}
}
}

View File

@ -29,6 +29,9 @@
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat2 = 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();
@ -120,6 +123,9 @@
panel4 = new Panel();
panel5 = new Panel();
groupBox2 = new GroupBox();
canvas3 = new XKRS.UI.Canvas();
canvas2 = new XKRS.UI.Canvas();
canvas1 = new XKRS.UI.Canvas();
originMatShow = new PictureBox();
ResultMatShow = new PictureBox();
panel8 = new Panel();
@ -178,6 +184,7 @@
timer6 = new System.Windows.Forms.Timer(components);
richTextBox1 = new RichTextBox();
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
CloseDecBtn = new Button();
tabPage2.SuspendLayout();
panel1.SuspendLayout();
groupBox5.SuspendLayout();
@ -1188,6 +1195,9 @@
// groupBox2
//
groupBox2.AutoSize = true;
groupBox2.Controls.Add(canvas3);
groupBox2.Controls.Add(canvas2);
groupBox2.Controls.Add(canvas1);
groupBox2.Controls.Add(originMatShow);
groupBox2.Controls.Add(ResultMatShow);
groupBox2.Location = new Point(0, 0);
@ -1200,6 +1210,70 @@
groupBox2.Text = "图片";
groupBox2.Enter += groupBox2_Enter;
//
// canvas3
//
canvas3.AllowSelectDefect = true;
canvas3.BrushColor = null;
canvas3.ImagePath = "";
mat1.IsEnabledDispose = true;
canvas3.ImaMAt = mat1;
canvas3.ImgData = null;
canvas3.Location = new Point(8, 467);
canvas3.MoveStep = 5F;
canvas3.Name = "canvas3";
canvas3.Route = 0D;
canvas3.Scale = 1D;
canvas3.Size = new Size(351, 223);
canvas3.TabIndex = 6;
canvas3.WholeScale = 0F;
canvas3.XMove = 0F;
canvas3.XScale = 0F;
canvas3.YMove = 0F;
canvas3.YScale = 0F;
//
// canvas2
//
canvas2.AllowSelectDefect = true;
canvas2.BrushColor = null;
canvas2.ImagePath = "";
mat2.IsEnabledDispose = true;
canvas2.ImaMAt = mat2;
canvas2.ImgData = null;
canvas2.Location = new Point(367, 240);
canvas2.MoveStep = 5F;
canvas2.Name = "canvas2";
canvas2.Route = 0D;
canvas2.Scale = 1D;
canvas2.Size = new Size(363, 205);
canvas2.TabIndex = 5;
canvas2.WholeScale = 0F;
canvas2.XMove = 0F;
canvas2.XScale = 0F;
canvas2.YMove = 0F;
canvas2.YScale = 0F;
//
// canvas1
//
canvas1.AllowSelectDefect = true;
canvas1.BrushColor = null;
canvas1.ImagePath = "";
mat3.IsEnabledDispose = true;
canvas1.ImaMAt = mat3;
canvas1.ImgData = null;
canvas1.Location = new Point(8, 237);
canvas1.MoveStep = 5F;
canvas1.Name = "canvas1";
canvas1.Route = 0D;
canvas1.Scale = 1D;
canvas1.Size = new Size(351, 208);
canvas1.TabIndex = 4;
canvas1.WholeScale = 0F;
canvas1.XMove = 0F;
canvas1.XScale = 0F;
canvas1.YMove = 0F;
canvas1.YScale = 0F;
canvas1.Load += canvas1_Load;
//
// originMatShow
//
originMatShow.Location = new Point(8, 21);
@ -1222,6 +1296,7 @@
//
// panel8
//
panel8.Controls.Add(CloseDecBtn);
panel8.Controls.Add(label24);
panel8.Controls.Add(ScannerBox);
panel8.Controls.Add(textBox2);
@ -1324,7 +1399,7 @@
//
// OKDNum
//
OKDNum.Location = new Point(130, 196);
OKDNum.Location = new Point(129, 249);
OKDNum.Margin = new Padding(4, 2, 4, 2);
OKDNum.Name = "OKDNum";
OKDNum.ReadOnly = true;
@ -1334,7 +1409,7 @@
// label20
//
label20.AutoSize = true;
label20.Location = new Point(32, 201);
label20.Location = new Point(31, 254);
label20.Margin = new Padding(4, 0, 4, 0);
label20.Name = "label20";
label20.Size = new Size(56, 17);
@ -1343,7 +1418,7 @@
//
// NGDNum
//
NGDNum.Location = new Point(130, 153);
NGDNum.Location = new Point(129, 206);
NGDNum.Margin = new Padding(4, 2, 4, 2);
NGDNum.Name = "NGDNum";
NGDNum.ReadOnly = true;
@ -1353,7 +1428,7 @@
// label19
//
label19.AutoSize = true;
label19.Location = new Point(32, 156);
label19.Location = new Point(31, 209);
label19.Margin = new Padding(4, 0, 4, 0);
label19.Name = "label19";
label19.Size = new Size(57, 17);
@ -1362,7 +1437,7 @@
//
// AllDSum
//
AllDSum.Location = new Point(130, 111);
AllDSum.Location = new Point(129, 164);
AllDSum.Margin = new Padding(4, 2, 4, 2);
AllDSum.Name = "AllDSum";
AllDSum.ReadOnly = true;
@ -1372,7 +1447,7 @@
// label18
//
label18.AutoSize = true;
label18.Location = new Point(32, 114);
label18.Location = new Point(31, 167);
label18.Margin = new Padding(4, 0, 4, 0);
label18.Name = "label18";
label18.Size = new Size(50, 17);
@ -1747,6 +1822,17 @@
richTextBox1.TabIndex = 1;
richTextBox1.Text = "";
//
// CloseDecBtn
//
CloseDecBtn.Location = new Point(170, 109);
CloseDecBtn.Margin = new Padding(4, 2, 4, 2);
CloseDecBtn.Name = "CloseDecBtn";
CloseDecBtn.Size = new Size(121, 40);
CloseDecBtn.TabIndex = 20;
CloseDecBtn.Text = "关闭检测";
CloseDecBtn.UseVisualStyleBackColor = true;
CloseDecBtn.Click += CloseDecBtn_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(8F, 17F);
@ -1955,8 +2041,8 @@
private Label label35;
private TextBox textBox2;
private Label label36;
private XKRS.UI.Canvas canvas5;
private XKRS.UI.Canvas canvas4;
//private XKRS.UI.Canvas canvas5;
//private XKRS.UI.Canvas canvas4;
private XKRS.UI.Canvas canvas3;
private XKRS.UI.Canvas canvas1;
private XKRS.UI.Canvas canvas6;
@ -1964,5 +2050,6 @@
private Button button1;
private Label label24;
private TextBox ScannerBox;
private Button CloseDecBtn;
}
}

View File

@ -40,6 +40,11 @@ namespace HisenceYoloDetection
{
public partial class MainForm : Form
{
enum MeachineState
{
machine_opening,
machine_closing,
}
public MainForm()
{
InitializeComponent();
@ -49,6 +54,7 @@ namespace HisenceYoloDetection
//OnDetectionDone += Defet_OnDetectionDone;
};
}
MeachineState meachineState= MeachineState.machine_closing;
MGSCameraDriver Cam1 = new MGSCameraDriver();
MGSCameraDriver Cam2 = new MGSCameraDriver();
public static string RootPath = "D:\\Hisence\\SQLImages\\";
@ -408,8 +414,8 @@ namespace HisenceYoloDetection
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
string jsonData = @"
{
""StartTime"": ""2024-07-15"",
""EndTime"": ""2024-07-15"",
""StartTime"": ""2024-07-1"",
""EndTime"": ""2024-07-22"",
""LineBody"": ""BZ-PC""
}";
@ -421,23 +427,16 @@ namespace HisenceYoloDetection
string response = PostData(url, postData);
string productType = null;
// 解析并处理响应
string finalDefIdToFind = m_sKEYENCEBar.Substring(0, m_sKEYENCEBar.Length - 7); // 目标 FinalDefID
string productType = FindStringAfterColon(response, finalDefIdToFind);
if (productType != null)
productType = FindStringAfterColon(response, finalDefIdToFind);
if (productType == null)
{
Console.WriteLine($"{finalDefIdToFind}: {productType}");
// 将结果写入文件
}
else
{
Console.WriteLine($"FinalDefID {finalDefIdToFind} not found in response.");
finalDefIdToFind = finalDefIdToFind.Substring(0, finalDefIdToFind.Length - 6);
productType = FindStringAfterColon(response, finalDefIdToFind);
}
}
catch (Exception ex)
{
@ -454,6 +453,15 @@ namespace HisenceYoloDetection
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
string path22 = "D:\\Hisence\\test2\\222.jpg";
Mat pathmat2 = Cv2.ImRead(path22);
string path222 = "D:\\Hisence\\test2\\111.jpg";
Rect rect1 = new Rect(0, 0, 0, 0);
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect1, rect1, true, "D://Hisence//test2");
Stopwatch sw = new Stopwatch();
sw.Start();
@ -897,7 +905,7 @@ namespace HisenceYoloDetection
try
{
//初始化相机
meachineState = MeachineState.machine_opening;//状态机设置成OPen
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
//dataGridView1.DataSource = dataSet.Tables[0];
@ -1440,7 +1448,7 @@ namespace HisenceYoloDetection
int iNum0 = 0;
int iNum3 = 0;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (true)
while (meachineState==MeachineState.machine_opening)
{
// myResetEvent.Set();
PLC548 = true;
@ -1456,7 +1464,7 @@ namespace HisenceYoloDetection
}
if (iNum0 >= 1)
{
while (true)
while (meachineState == MeachineState.machine_opening)
{
bTriger = false;
@ -1485,7 +1493,7 @@ namespace HisenceYoloDetection
_runHandleBefore.WaitOne();
//这里改成和海信的对接需求
string OcrBar = "";
string FinalDefIDToFind = m_sKEYENCEBar.Substring(1, 18);// 目标 FinalDefID
string FinalDefIDToFind = m_sKEYENCEBar;// 目标 FinalDefID
this.Invoke(new Action(() =>
{
@ -1504,7 +1512,8 @@ namespace HisenceYoloDetection
if (OcrBar.IsNullOrEmpty())
{
break;
myLog("Mes系统近日无型号" + m_sKEYENCEBar, DateTime.Now);
//break;
}
xKNow = GetModeFromBar(OcrBar);//从数据库中查询到这个条码的四轴的值
@ -1653,7 +1662,7 @@ namespace HisenceYoloDetection
}
if(iNum3>=2)
if (iNum3 >= 2)
{
melsecPLCTCPDriver.WriteInt("550", 1);//阻塞
}
@ -1806,15 +1815,18 @@ namespace HisenceYoloDetection
// IOcrBAr = "W821PWMS27106WD2";
// IOcrBAr=
//根据条码数据库比对
_runHandleAfter.Reset();
if (xKNow == null)
{
myLog("未匹配条码" , DateTime.Now);
myLog("未匹配条码", DateTime.Now);
break;
}
if (xKNow.OcrBar == null)
{
myLog("未匹配成功" + xKNow.OcrBar, DateTime.Now);
myLog("开始插入模板", DateTime.Now);
//Insert_auto();
break;
}
string IOcrBAr = xKNow.OcrBar;
@ -1822,7 +1834,7 @@ namespace HisenceYoloDetection
//这里改成和海信的对接需求
IfCam1TwoTriger = false;
_runHandleAfter.Reset();
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
if (xkWordList.Count() == 1)
{
@ -1931,9 +1943,8 @@ namespace HisenceYoloDetection
}
//排序比对块
HashSet<string> set1 = new HashSet<string>(listLabels);
HashSet<string> set2 = new HashSet<string>(RealLabels);
bool MatchStr = set1.SetEquals(set2);
bool MatchStr = listLabels.SequenceEqual(RealLabels);
#endregion
//块比对完了 进行详细比对
if (MatchStr)
@ -1984,52 +1995,60 @@ namespace HisenceYoloDetection
}));
}
else
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
//加上人为判断是否是NG洗衣机
DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
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;
}));
myLog("匹配失败", DateTime.Now);
}
else
{
NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
myLog("匹配失败", DateTime.Now);
//界面显示
// InsertXK_HisenceWordMatchData(xK_MatchDet, true);
this.Invoke(new Action(() =>
{
OKOrNGShow.Image = NGbitmap;
}));
myLog("匹配成功", DateTime.Now);
}
//melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
//melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
//melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
//melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
////加上人为判断是否是NG洗衣机
//DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
//if (dr == DialogResult.OK)
//{
// melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
// melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
// 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;
// }));
// myLog("匹配失败", DateTime.Now);
//}
//else
//{
// NGDsums++;
// melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
// melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
// melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
// this.Invoke(new Action(() =>
// {
// OKOrNGShow.Image = NGbitmap;
// }));
// myLog("匹配成功", DateTime.Now);
//}
@ -2038,10 +2057,7 @@ namespace HisenceYoloDetection
}
}
catch (Exception e)
{
throw e;
}
finally
{
@ -2061,7 +2077,8 @@ namespace HisenceYoloDetection
/// </summary>
public void ThreadPost()
{
Task.Run(() => {
Task.Run(() =>
{
while (true)
{
@ -2316,30 +2333,30 @@ 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);
//string path22 = "D:\\Hisence\\test2\\002.jpg";
//Mat pathmat2 = Cv2.ImRead(path22);
//string path222 = "D:\\Hisence\\test2\\001.jpg";
//Rect rect1 = new Rect(1929, 745, 396, 377);
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
//CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect1, rect1, true, "D://Hisence//Test2");
string path = "D:\\Hisence\\Test1\\1.png";
Mat pathmat =Cv2.ImRead(path);
string path2 = "D:\\Hisence\\Test1\\2.png";
//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);
//Rect rect2 = new Rect(0, 0, 0, 0);
//CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//test2");
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
*/
// OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
meachineState = MeachineState.machine_opening;
TriggerCameral2();//光电触发拍照 根据SN获取型号 从数据库中得到块值
ReadyDetect();//相机拍照后检测线程
//ThreadPost();//相机拍照后获取当日的型号
@ -2690,13 +2707,13 @@ namespace HisenceYoloDetection
}
public string FormBarType(string SN)
{
string productType = "N/A";
string productType = "null";
string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
string jsonData = @"
{
""StartTime"": ""2024-07-15"",
""EndTime"": ""2024-07-15"",
""StartTime"": ""2024-07-1"",
""EndTime"": ""2024-07-22"",
""LineBody"": ""BZ-PC""
}";
@ -2712,19 +2729,12 @@ namespace HisenceYoloDetection
// 解析并处理响应
string finalDefIdToFind = m_sKEYENCEBar.Substring(0, m_sKEYENCEBar.Length - 7); // 目标 FinalDefID
productType = FindStringAfterColon(response, finalDefIdToFind);
if (productType != null)
if (productType == null)
{
Console.WriteLine($"{finalDefIdToFind}: {productType}");
// 将结果写入文件
}
else
{
Console.WriteLine($"FinalDefID {finalDefIdToFind} not found in response.");
finalDefIdToFind = finalDefIdToFind.Substring(0, finalDefIdToFind.Length - 6);
productType = FindStringAfterColon(response, finalDefIdToFind);
}
}
catch (Exception ex)
{
@ -2735,6 +2745,121 @@ namespace HisenceYoloDetection
// sw.Stop();
// Console.WriteLine("时间请求i" + sw.ElapsedMilliseconds);
}
public void Insert_auto(bool ifwhiteBan, Mat img, string SNtext, int MoveX, int MoveY, int MoveZ)
{
// PaddleOcrModel IpaddleOcrModel = new PaddleOcrModel();
// IpaddleOcrModel.Load(ModelChangePath, "CPU");
string IOcrBAr = FormBarType(SNtext);
XK_HisenceWord xkWord = new XK_HisenceWord();
xkWord.OcrBar = IOcrBAr;
xkWord.TwoIFWhile = ifwhiteBan;
using (StreamWriter sw = new StreamWriter("D://123.log", true))
{
sw.WriteLine("\n");
sw.WriteLine(IOcrBAr);
sw.Flush();
}
//将所有的块裁剪 识别字符对比字符串
//进行推理
//从第一次拍照全图范围内目标检测然后进行OCR识别
MLRequest CamOneI = new MLRequest();
CamOneI.currentMat = Cv2.ImRead(Cam1OnePath);
CamOneI.ResizeWidth = 640;
CamOneI.ResizeHeight = 640;
CamOneI.Score = 0.3f;
CamOneI.in_lable_path = LablePath;//标签路径
CamOneI.confThreshold = 0.3f;//模型置信度
CamOneI.iouThreshold = 0.4f;//检测IOU
CamOneI.out_node_name = "output";
MLResult mL3 = simboObjectDetection.RunInferenceFixed(CamOneI);
MLResult mLButton = simboObjectDetButton.RunInferenceFixed(CamOneI);
//if (mL3.IsSuccess)
//{
// DateTime dt = DateTime.Now;
// mL3.ResultMap.Save("D:\\Hisence\\detImages\\" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
//}
List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = CamOneI.currentMat.Clone();
//Mat mCut = new Mat();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
InsertSqlRunDataButton(ref keyValueResult, true, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
InsertXKHisenceWordData(xkWord);//往关键字表中插入一条数据
//文本区域
//List<string> bingji = strMatListOne.Union(strMatListTwo).ToList();//并(全)集
//List<string> Fuzzybingji = strMatFuzzyListOne.Union(strMatFuzzyListTwo).ToList();//并(全)集
string OcrTextone = strMatListOne.Join("##");
string OcrTextTwo = strMatFuzzyListOne.Join("##");
//string OcrTextinsert = "";
//List<string> bingji = strMatListListOne.Union(strMatListListTwo).ToList();//并(全)集
//for (int j = 0; j < bingji.Count; j++)
//{
// string jdetial = bingji[j];
// OcrTextinsert += jdetial + "##";
//}
string detstr = "";
//找到识别区域
MLResult MLsum = mL3;
//for (int v = 0; v < mL4.ResultDetails.Count; v++)
//{
// MLsum.ResultDetails.Add(mL4.ResultDetails[v]);
//}
for (int v = 0; v < MLsum.ResultDetails.Count; v++)
{
if (v < MLsum.ResultDetails.Count - 1)
{
detstr += MLsum.ResultDetails[v].LabelName + ",";
}
else
{
detstr += MLsum.ResultDetails[v].LabelName;
}
}
DateTime dt2 = DateTime.Now;
XKHisence xK = new XKHisence("1", IOcrBAr, MoveX, MoveY, MoveZ, detstr, OcrTextone, MoveX, MoveY, MoveZ, ModelChangePath, "", OcrTextTwo);
//string log="D:\\Hisence\\detImages\\" + dt2.Year.ToString() + dt2.Month.ToString() + dt2.Day.ToString() + dt2.Hour.ToString() + dt2.Minute.ToString() + dt2.Millisecond.ToString() + "2result.log";
// using (StreamWriter sw=new StreamWriter(log, true))
// {
// // sw.WriteLine(xK.OcrBar+"\n");
// sw.WriteLine(xK.OcrText);
// sw.WriteLine(xK.FuzzyOcrText);
// }
//IpaddleOcrModel.FreeModel();
string sql = "insert into XK_Hisence VALUES('" + xK.Type + "','" + xK.OcrBar + "'," + xK.MoveX + "," + xK.MoveY + "," + xK.MoveZ + ",'" + xK.Detect + "','" + xK.OcrText + "'," + xK.MoveTwoX + "," + xK.MoveTwoY + "," + xK.MoveTwoZ + ",'" + xK.OcrParm + "','" + xK.Language + "','" + xK.FuzzyOcrText + "')";
int i = SQLiteHelper.ExecuteSql(sql);
if (i == 1)
{
myLog("插入成功", DateTime.Now);
//MessageBox.Show("XK_Hisence插入一条数据");
}
//bool ismatch = IsMatchOcrText("WF3S7021BB", strMatListListOne);
//相机回调
}
public void InsertXK_Hisence(bool ifwhiteBan, string SNtext, int MoveX, int MoveY, int MoveZ)
{
// PaddleOcrModel IpaddleOcrModel = new PaddleOcrModel();
@ -2949,7 +3074,7 @@ namespace HisenceYoloDetection
int iv = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
if (iv == 1)
{
MessageBox.Show("关键字XK_HisenceWord插入一条数据");
//MessageBox.Show("关键字XK_HisenceWord插入一条数据");
}
}
public void InsertXK_HisenceWordMatchData(XK_HisenceWord xkWord, bool ifMatch)
@ -3190,16 +3315,16 @@ namespace HisenceYoloDetection
canvas3.ImaMAt = detectionImage;
}
break;
case 4:
{
canvas4.ImaMAt = detectionImage;
}
break;
case 5:
{
canvas5.ImaMAt = detectionImage;
}
break;
//case 4:
// {
// canvas4.ImaMAt = detectionImage;
// }
// break;
//case 5:
// {
// canvas5.ImaMAt = detectionImage;
// }
// break;
case 6:
{
//canvas6.ImaMAt = detectionImage;
@ -3242,6 +3367,7 @@ 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))
@ -3249,64 +3375,77 @@ namespace HisenceYoloDetection
sw.WriteLine(filename + "\n");
sw.Flush();
}
// 克隆当前图像
Mat mResultCut = currentMatC.Clone();
Rect areaBlack = new Rect();
//旋钮的位置
// 旋钮的位置
if (cam1Button.ResultDetails.Count == 1)
{
Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1Button.ResultDetails[0].Rect.X;
int rectsy = cam1Button.ResultDetails[0].Rect.Y;
int rectsWidth = cam1Button.ResultDetails[0].Rect.Width;
int rectsHeight = cam1Button.ResultDetails[0].Rect.Height;
// 修正旋钮位置,防止负数
rectsx = Math.Max(rectsx, 0);
rectsy = Math.Max(rectsy, 0);
rectsWidth = Math.Min(rectsWidth, currentMatC.Width - rectsx);
rectsHeight = Math.Min(rectsHeight, currentMatC.Height - rectsy);
areaBlack = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
}
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
{
Mat mResultCuti = mResultCut.Clone();
int rectsx = cam1TwoML.ResultDetails[i].Rect.X;
int rectsy = cam1TwoML.ResultDetails[i].Rect.Y;
int rectsWidth = cam1TwoML.ResultDetails[i].Rect.Width;
int rectsHeight = cam1TwoML.ResultDetails[i].Rect.Height;
// 修正区域位置,防止负数
rectsx = Math.Max(rectsx, 0);
rectsy = Math.Max(rectsy, 0);
rectsWidth = Math.Min(rectsWidth, currentMatC.Width - rectsx);
rectsHeight = Math.Min(rectsHeight, currentMatC.Height - rectsy);
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
if (keyValueResult.Keys.Contains(blockIndex))
{
int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex);
int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X;
if (rectsx > rectsxof)
{
blockIndex = "3";
}
}
Rect area2 = new Rect(0, 0, 0, 0);
Mat matCut = new Mat();
if (blockIndex == "2")//根据旋钮扩大范围
{
//如果旋钮在第三块板则旋钮的位置就是0,0,0,0
Rect area2 = new Rect(0, 0, 0, 0);
if (blockIndex == "2") // 根据旋钮扩大范围
{
if ((areaBlack.X + areaBlack.Width) < (rectsx + rectsWidth))
{
areaBlack.X -= rectsx;
areaBlack.Y -= rectsy;
areaBlack.X = Math.Max(areaBlack.X - rectsx, 0);
areaBlack.Y = Math.Max(areaBlack.Y - rectsy, 0);
areaBlack.Width = Math.Min(areaBlack.Width, currentMatC.Width - areaBlack.X);
areaBlack.Height = Math.Min(areaBlack.Height, currentMatC.Height - areaBlack.Y);
area2 = areaBlack;
}
string TwoRectStr = CheckDiffSciHelper.rectChangeStr(area2);
xK_HisenceWord.TwoRect = TwoRectStr;
}
Stopwatch sw = Stopwatch.StartNew();
sw.Start();
int extendHeight = 50;
rectsHeight += extendHeight;
rectsHeight = Math.Min(rectsHeight, currentMatC.Height - rectsy);
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
matCut = new Mat(mResultCuti, area);
//OCR识别裁剪图片
Mat matCut = new Mat(mResultCut, area);
// OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = paddleOcrModel.RunInference(reqcut);
@ -3316,10 +3455,8 @@ namespace HisenceYoloDetection
myLog("插入每块板需要的时间" + sw.ElapsedMilliseconds, DateTime.Now);
keyValueResult.Add(blockIndex, blockMatchI);
}
//}
//catch (Exception ex)
//{
@ -3419,7 +3556,7 @@ namespace HisenceYoloDetection
for (int j = 0; j < mLcut.ResultDetails.Count; j++)
{
var resultDetail = mLcut.ResultDetails[j];
if (resultDetail.Score > 0.8)
if (resultDetail.Score > 0.7)
{
string jdetial = mLcut.ResultDetails[j].LabelDisplay;
string result = Regex.Replace(jdetial, "[ \\[ \\] \\^ \\-_*×――(^)$%~!@#$…&%¥—+=<>《》!??:?`·、。,;,.;/\"‘’“”-]", "");
@ -3545,157 +3682,157 @@ namespace HisenceYoloDetection
}
}
break;
case "4"://贴纸匹配
{
xK_HisenceWord.FourblockPath = CutSavePath;
xK_HisenceWord.FourblockMainWord = MainWoidStr;
xK_HisenceWord.FourblockText = TextWoidStr;
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.FourblockMainWord;
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
//case "4"://贴纸匹配
// {
// xK_HisenceWord.FourblockPath = CutSavePath;
// xK_HisenceWord.FourblockMainWord = MainWoidStr;
// xK_HisenceWord.FourblockText = TextWoidStr;
// if (!saveimage)
// {
// SQLStr = SQlxK_HisenceWord.FourblockMainWord;
// bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FourblockMainWord, SQlxK_HisenceWord.FourblockMainWord);
Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.FourblockPath;
// 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;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 4);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 4);
}
}
}
break;
case "5"://贴纸匹配
{
xK_HisenceWord.FiveblockPath = CutSavePath;
xK_HisenceWord.FiveblockMainWord = MainWoidStr;
xK_HisenceWord.FiveblockText = TextWoidStr;
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.FiveblockMainWord;
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;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 5);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 5);
}
}
}
break;
case "6"://贴纸匹配
{
xK_HisenceWord.SixblockPath = CutSavePath;
xK_HisenceWord.SixblockMainWord = MainWoidStr;
xK_HisenceWord.SixblockText = TextWoidStr;
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.SixblockMainWord;
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
OneIF1 = false;//测试
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;
// juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
// if (!OneIF1 || !juanjiMatch)
// {
// OneIF = false;
// DisplayResult(mLcut);
//显示错误的板
// mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 6);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 6);
}
// //显示错误的板
// // mLcut.ResultMap;
// Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 4);
// }
// else
// {
// OneIF = true;
// Defet_OnDetectionDone(OKMat, 4);
// }
}
}
break;
case "7"://贴纸匹配
{
xK_HisenceWord.SevenblockPath = CutSavePath;
xK_HisenceWord.SevenblockMainWord = MainWoidStr;
xK_HisenceWord.SevenblockText = TextWoidStr;
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
// }
// }
// break;
//case "5"://贴纸匹配
// {
// xK_HisenceWord.FiveblockPath = CutSavePath;
// xK_HisenceWord.FiveblockMainWord = MainWoidStr;
// xK_HisenceWord.FiveblockText = TextWoidStr;
// if (!saveimage)
// {
// SQLStr = SQlxK_HisenceWord.FiveblockMainWord;
// bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.FiveblockMainWord, SQlxK_HisenceWord.FiveblockMainWord);
// Rect rect = new Rect(0, 0, 0, 0);
// string PathSql = SQlxK_HisenceWord.FiveblockMainWord;
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;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 7);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 7);
}
}
}
break;
case "8"://贴纸匹配
{
xK_HisenceWord.EightblockPath = CutSavePath;
xK_HisenceWord.EightblockMainWord = MainWoidStr;
xK_HisenceWord.EightblockText = TextWoidStr;
if (!saveimage)
{
SQLStr = SQlxK_HisenceWord.EightblockMainWord;
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;
// juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, rect, rect, false, "D://Hisence//Test");
// if (!OneIF1 || !juanjiMatch)
// {
// OneIF = false;
// DisplayResult(mLcut);
//显示错误的板
// mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 8);
}
else
{
OneIF = true;
Defet_OnDetectionDone(OKMat, 8);
}
}
}
break;
// //显示错误的板
// // mLcut.ResultMap;
// Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 5);
// }
// else
// {
// OneIF = true;
// Defet_OnDetectionDone(OKMat, 5);
// }
// }
// }
// break;
//case "6"://贴纸匹配
// {
// xK_HisenceWord.SixblockPath = CutSavePath;
// xK_HisenceWord.SixblockMainWord = MainWoidStr;
// xK_HisenceWord.SixblockText = TextWoidStr;
// if (!saveimage)
// {
// SQLStr = SQlxK_HisenceWord.SixblockMainWord;
// bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SixblockMainWord, SQlxK_HisenceWord.SixblockMainWord);
// OneIF1 = false;//测试
// 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;
// Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 6);
// }
// else
// {
// OneIF = true;
// Defet_OnDetectionDone(OKMat, 6);
// }
// }
// }
// break;
//case "7"://贴纸匹配
// {
// xK_HisenceWord.SevenblockPath = CutSavePath;
// xK_HisenceWord.SevenblockMainWord = MainWoidStr;
// xK_HisenceWord.SevenblockText = TextWoidStr;
// if (!saveimage)
// {
// SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
// 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;
// Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 7);
// }
// else
// {
// OneIF = true;
// Defet_OnDetectionDone(OKMat, 7);
// }
// }
// }
// break;
//case "8"://贴纸匹配
// {
// xK_HisenceWord.EightblockPath = CutSavePath;
// xK_HisenceWord.EightblockMainWord = MainWoidStr;
// xK_HisenceWord.EightblockText = TextWoidStr;
// if (!saveimage)
// {
// SQLStr = SQlxK_HisenceWord.EightblockMainWord;
// 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;
// Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 8);
// }
// else
// {
// OneIF = true;
// Defet_OnDetectionDone(OKMat, 8);
// }
// }
// }
// break;
}
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString();
string txtLog = "D://Hisence//" + filename + "logsMatch.log";
@ -3787,9 +3924,27 @@ namespace HisenceYoloDetection
{
if (!m_sKEYENCEBar.IsNullOrEmpty())
{
OcrBarBox.Text = m_sKEYENCEBar.Substring(0, m_sKEYENCEBar.Length - 7);
OcrBarBox.Text = m_sKEYENCEBar;
}
}
private void canvas1_Load(object sender, EventArgs e)
{
}
private void canvas7_Load(object sender, EventArgs e)
{
}
private void CloseDecBtn_Click(object sender, EventArgs e)
{
meachineState = MeachineState.machine_closing;
melsecPLCTCPDriver.WriteInt("550", 0);
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);
}
}
}

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>52</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">