修改流程卡顿

This commit is contained in:
YZJ 2024-08-26 17:45:30 +08:00
parent 2913bc722c
commit f90eb75c3b
4 changed files with 294 additions and 250 deletions

View File

@ -20,7 +20,7 @@ namespace HisenceYoloDetection
{
public static class CheckDiffSciHelper
{
public static Mat ProcessImage(Mat image, Rect fillRect)
{
@ -33,38 +33,38 @@ namespace HisenceYoloDetection
int rectX = 0;
int rectY = height - rectSize; // 确保是左下角
// 防止越界
// 检查左下角矩形框是否在图像范围内
if (rectY < 0 || rectX < 0 || rectSize > width || rectSize > height)
{
Console.WriteLine("图像尺寸不足以获取指定区域");
return image;
}
// 定义感兴趣区域 (ROI) 并计算其平均颜色
Rect roi = new Rect(rectX, rectY, rectSize, rectSize);
Mat roiMat = new Mat(image, roi);
// 计算平均颜色值
Scalar meanColor = Cv2.Mean(roiMat);
Vec3b fillColor = new Vec3b((byte)meanColor.Val0, (byte)meanColor.Val1, (byte)meanColor.Val2);
// 防止越界
if (fillRect.X < 0 || fillRect.Y < 0 || fillRect.X + fillRect.Width > width || fillRect.Y + fillRect.Height > height)
// 创建 Scalar 类型的颜色填充
Scalar fillColor = new Scalar(meanColor.Val0, meanColor.Val1, meanColor.Val2);
// 修改 fillRect 的 Y 和 Height 属性以覆盖整个图像的高度
fillRect.Y = 0; // 起始位置为顶部
fillRect.Height = height; // 高度覆盖整个图像
// 检查填充矩形是否在图像范围内
if (fillRect.X < 0 || fillRect.X + fillRect.Width > width)
{
Console.WriteLine("填充区域超出图像范围");
return image;
}
// 填充指定区域
for (int y = fillRect.Y; y < fillRect.Y + fillRect.Height; y++)
{
for (int x = fillRect.X; x < fillRect.X + fillRect.Width; x++)
{
image.Set<Vec3b>(y, x, fillColor);
}
}
// 使用 OpenCV 的 rectangle 函数进行填充
Cv2.Rectangle(image, fillRect.TopLeft, fillRect.BottomRight, fillColor, Cv2.FILLED);
return image;
}
/// <summary>
///
/// </summary>
@ -267,7 +267,7 @@ namespace HisenceYoloDetection
double ratio1 = whiteArea1 / (thr1.Rows * thr1.Cols);
double ratio2 = whiteArea2 / (thr2.Rows * thr2.Cols);
if (Math.Abs(ratio1 - ratio2) >= 0.95)
if (Math.Abs(ratio1 - ratio2) >= 0.90)
{
isMatch = true;
}

View File

@ -35,40 +35,44 @@
//
// button1
//
button1.Location = new Point(301, 82);
button1.Location = new Point(192, 58);
button1.Margin = new Padding(2, 2, 2, 2);
button1.Name = "button1";
button1.Size = new Size(112, 34);
button1.Size = new Size(71, 24);
button1.TabIndex = 0;
button1.Text = "验证";
button1.UseVisualStyleBackColor = true;
//
// textBox1
//
textBox1.Location = new Point(224, 34);
textBox1.Location = new Point(143, 24);
textBox1.Margin = new Padding(2, 2, 2, 2);
textBox1.Name = "textBox1";
textBox1.Size = new Size(269, 30);
textBox1.Size = new Size(173, 23);
textBox1.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(91, 34);
label1.Location = new Point(58, 24);
label1.Margin = new Padding(2, 0, 2, 0);
label1.Name = "label1";
label1.Size = new Size(100, 24);
label1.Size = new Size(68, 17);
label1.TabIndex = 2;
label1.Text = "退出密码:";
label1.Text = "输入密码:";
label1.Click += label1_Click;
//
// Form2
//
AutoScaleDimensions = new SizeF(11F, 24F);
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(674, 130);
ClientSize = new Size(429, 92);
Controls.Add(label1);
Controls.Add(textBox1);
Controls.Add(button1);
Margin = new Padding(2, 2, 2, 2);
Name = "Form2";
Text = "退出验证";
Text = "验证身份";
Load += Form2_Load;
ResumeLayout(false);
PerformLayout();

View File

@ -123,6 +123,8 @@
panel4 = new Panel();
panel5 = new Panel();
groupBox9 = new GroupBox();
label38 = new Label();
statusButton = new Button();
DevNameCombo = new ComboBox();
ScanDevList = new Button();
groupBox2 = new GroupBox();
@ -232,7 +234,7 @@
tabPage2.Margin = new Padding(4, 2, 4, 2);
tabPage2.Name = "tabPage2";
tabPage2.Padding = new Padding(4, 2, 4, 2);
tabPage2.Size = new Size(1276, 923);
tabPage2.Size = new Size(1276, 900);
tabPage2.TabIndex = 1;
tabPage2.Text = "PLC";
tabPage2.UseVisualStyleBackColor = true;
@ -915,7 +917,7 @@
tabPage1.Margin = new Padding(4, 2, 4, 2);
tabPage1.Name = "tabPage1";
tabPage1.Padding = new Padding(4, 2, 4, 2);
tabPage1.Size = new Size(1276, 923);
tabPage1.Size = new Size(1276, 900);
tabPage1.TabIndex = 0;
tabPage1.Text = "相机";
tabPage1.UseVisualStyleBackColor = true;
@ -1215,6 +1217,8 @@
//
// groupBox9
//
groupBox9.Controls.Add(label38);
groupBox9.Controls.Add(statusButton);
groupBox9.Controls.Add(DevNameCombo);
groupBox9.Controls.Add(ScanDevList);
groupBox9.Location = new Point(8, 16);
@ -1225,21 +1229,40 @@
groupBox9.Text = "设备状态";
groupBox9.Enter += groupBox9_Enter;
//
// label38
//
label38.AutoSize = true;
label38.Location = new Point(272, 36);
label38.Margin = new Padding(4, 0, 4, 0);
label38.Name = "label38";
label38.Size = new Size(64, 17);
label38.TabIndex = 26;
label38.Text = "设备状态";
label38.Click += label38_Click;
//
// statusButton
//
statusButton.Location = new Point(367, 22);
statusButton.Name = "statusButton";
statusButton.Size = new Size(98, 46);
statusButton.TabIndex = 3;
statusButton.UseVisualStyleBackColor = true;
//
// DevNameCombo
//
DevNameCombo.FormattingEnabled = true;
DevNameCombo.Location = new Point(8, 33);
DevNameCombo.Margin = new Padding(4, 2, 4, 2);
DevNameCombo.Name = "DevNameCombo";
DevNameCombo.Size = new Size(524, 25);
DevNameCombo.Size = new Size(161, 25);
DevNameCombo.TabIndex = 1;
//
// ScanDevList
//
ScanDevList.Location = new Point(557, 33);
ScanDevList.Location = new Point(557, 22);
ScanDevList.Margin = new Padding(4, 2, 4, 2);
ScanDevList.Name = "ScanDevList";
ScanDevList.Size = new Size(94, 35);
ScanDevList.Size = new Size(94, 46);
ScanDevList.TabIndex = 2;
ScanDevList.Text = "Scan";
ScanDevList.UseVisualStyleBackColor = true;
@ -1400,7 +1423,7 @@
//
// textBox4
//
textBox4.Location = new Point(529, 93);
textBox4.Location = new Point(463, 93);
textBox4.Margin = new Padding(4, 2, 4, 2);
textBox4.Name = "textBox4";
textBox4.ReadOnly = true;
@ -1410,7 +1433,7 @@
// label36
//
label36.AutoSize = true;
label36.Location = new Point(426, 99);
label36.Location = new Point(392, 93);
label36.Name = "label36";
label36.Size = new Size(64, 17);
label36.TabIndex = 17;
@ -1440,17 +1463,17 @@
//
// AllDSum
//
AllDSum.Location = new Point(111, 64);
AllDSum.Location = new Point(86, 64);
AllDSum.Margin = new Padding(4, 2, 4, 2);
AllDSum.Name = "AllDSum";
AllDSum.ReadOnly = true;
AllDSum.Size = new Size(74, 23);
AllDSum.Size = new Size(64, 23);
AllDSum.TabIndex = 6;
//
// label19
//
label19.AutoSize = true;
label19.Location = new Point(205, 96);
label19.Location = new Point(173, 93);
label19.Margin = new Padding(4, 0, 4, 0);
label19.Name = "label19";
label19.Size = new Size(71, 17);
@ -1459,7 +1482,7 @@
//
// NGDNum
//
NGDNum.Location = new Point(331, 96);
NGDNum.Location = new Point(265, 90);
NGDNum.Margin = new Padding(4, 2, 4, 2);
NGDNum.Name = "NGDNum";
NGDNum.ReadOnly = true;
@ -1478,7 +1501,7 @@
//
// OKDNum
//
OKDNum.Location = new Point(331, 35);
OKDNum.Location = new Point(265, 41);
OKDNum.Margin = new Padding(4, 2, 4, 2);
OKDNum.Name = "OKDNum";
OKDNum.ReadOnly = true;
@ -1488,7 +1511,7 @@
// label20
//
label20.AutoSize = true;
label20.Location = new Point(206, 41);
label20.Location = new Point(173, 41);
label20.Margin = new Padding(4, 0, 4, 0);
label20.Name = "label20";
label20.Size = new Size(70, 17);
@ -1497,7 +1520,7 @@
//
// textBox1
//
textBox1.Location = new Point(529, 42);
textBox1.Location = new Point(463, 41);
textBox1.Margin = new Padding(4, 2, 4, 2);
textBox1.Name = "textBox1";
textBox1.ReadOnly = true;
@ -1507,7 +1530,7 @@
// label35
//
label35.AutoSize = true;
label35.Location = new Point(426, 45);
label35.Location = new Point(392, 44);
label35.Name = "label35";
label35.Size = new Size(50, 17);
label35.TabIndex = 14;
@ -1683,7 +1706,7 @@
tabPage3.Location = new Point(4, 26);
tabPage3.Margin = new Padding(4, 2, 4, 2);
tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(1276, 923);
tabPage3.Size = new Size(1276, 900);
tabPage3.TabIndex = 4;
tabPage3.Text = "录入新型号";
tabPage3.UseVisualStyleBackColor = true;
@ -2037,6 +2060,7 @@
panel5.ResumeLayout(false);
panel5.PerformLayout();
groupBox9.ResumeLayout(false);
groupBox9.PerformLayout();
groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
((System.ComponentModel.ISupportInitialize)originMatShow).EndInit();
@ -2242,5 +2266,8 @@
private Button button4;
private Button button5;
private Button button6;
private Label label38;
private Button button7;
private Button statusButton;
}
}

View File

@ -79,7 +79,7 @@ namespace HisenceYoloDetection
ManualResetEvent _runHandleAfter = new ManualResetEvent(false);
AutoResetEvent _runThreadFormtype = new AutoResetEvent(false);
bool PLC545 = false;
private const string CorrectPassword = "12345";
private const string CorrectPassword = "628628";
bool PLC548 = false;
string m_sKEYENCEBar;
@ -912,7 +912,8 @@ namespace HisenceYoloDetection
meachineState = MeachineState.machine_opening;//状态机设置成OPen
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
//dataGridView1.DataSource = dataSet.Tables[0];
statusButton.BackColor = Color.Red; // 设备停止
statusButton.Text = "停止"; // 更新文本
Cam1.Start("Cam1");
if (Cam1.IfSuccess)
{
@ -1315,15 +1316,6 @@ namespace HisenceYoloDetection
textBox3.Text = OcrBar;
}));
//myLog("扫码器结果" + m_sKEYENCEBar, DateTime.Now);
//#if false
//是否给Pos请求加上时间超时
//#else
// OcrBar = "OZ.洗衣机.WF3G7014-NVW001CZA.WSG374A.白";
//#endif
// if(Oldm_sKEYENCEBar!= m_sKEYENCEBar)
if (OcrBar.IsNullOrEmpty())
{
@ -1333,18 +1325,8 @@ namespace HisenceYoloDetection
xKNow = GetModeFromBar(OcrBar);//从数据库中查询到这个条码的四轴的值
//if (Regex.IsMatch(xKNow.MoveX.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveY.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveZ.ToString(), @"^[0-9]+$"))
//{
// // myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now);
//}
}
// Thread.Sleep(2);
bBar = false;
#if true
@ -1356,7 +1338,7 @@ namespace HisenceYoloDetection
myLog("第一次采集图像", DateTime.Now);
//移动模组 读三次测距的地址 看是否往前移动
MoveToP(5815, YPos, ZPos);
MoveToP(7815, YPos, ZPos);
// Thread.Sleep(2000);//删
@ -1376,34 +1358,15 @@ namespace HisenceYoloDetection
double dismove = disreal - 876;
if (dismove > -4000 && dismove < 4000)
{
MoveToP(5815, YPos, ZPos + (int)(dismove));
MoveToP(7815, YPos, ZPos + (int)(dismove));
}
Cam1.SnapshotCount = 0;
Cam1.Snapshot();
//Cam2.SnapshotCount = 0;
//Cam2.Snapshot();
//myLog("第二次采集图像", DateTime.Now);
//if (xKNow != null)
//{
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
//}
MoveToP(7815, YPos, ZPos);
// MoveToP(51043, YPos, ZPos + (int)(dismove));
//Cam1.Snapshot();
MoveToP(5815, YPos, ZPos);
//melsecPLCTCPDriver.WriteInt("550", 0);//方行
//Thread.Sleep(1000);//洗衣机可能过不去
//if (xKNow != null)
//{
// MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);
//}
myLog("采集图像成功", DateTime.Now);
//模组复位
@ -1559,7 +1522,7 @@ namespace HisenceYoloDetection
string pathfile = fitImageFolder + SN + ".jpg";
//CamShow1.ImaMAt = cameraMat;
cameraMat.ImWrite(pathfile);
CheckDiffSciHelper1.ResizeImage(pathfile, pathfile, 640, 480, 75);
}
/// <summary>
@ -1589,27 +1552,10 @@ namespace HisenceYoloDetection
{
//信号量阻塞 使其不在总数增加和闪烁
_runHandleAfter.WaitOne();
//melsecPLCTCPDriver.WriteInt("550", 0);//方行
//2第一次拍照
//if (IfCam2Triger)
//{
//根据条码数据库比对
_runHandleAfter.Reset();
//if (xKNow == null)
//{
// myLog("未匹配条码", DateTime.Now);
// break;
//}
//if (xKNow.OcrBar == null)
//{
// myLog("未匹配成功" + xKNow.OcrBar, DateTime.Now);
// myLog("开始插入模板", DateTime.Now);
// Insert_auto(true, Cam1ImgOne, m_sKEYENCEBar, 8974, 0, 0);
// break;
//}
if (m_sKEYENCEBar != null)
@ -1618,14 +1564,43 @@ namespace HisenceYoloDetection
{
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
myLog("开始插入模板", DateTime.Now);
Insert_auto(true, Cam1ImgOne, m_sKEYENCEBar, 8974, 0, 0);
Thread.Sleep(2000);
OcrBar = FormBarType(m_sKEYENCEBar);
xKNow = GetModeFromBar(OcrBar); // 重新获取
if (xKNow != null)
{
myLog("插入模板成功!", DateTime.Now);
DialogResult result = MessageBox.Show("是否插入新型号", "选择操作", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
//插入提示
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
if (result == DialogResult.Yes)
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
Insert_auto(true, Cam1ImgOne, m_sKEYENCEBar, 8974, 0, 0);
Thread.Sleep(2000);
OcrBar = FormBarType(m_sKEYENCEBar);
xKNow = GetModeFromBar(OcrBar); // 重新获取
if (xKNow != null)
{
myLog("插入模板成功!", DateTime.Now);
}
// 用户选择了“是”
else
{
continue;
}
}
else if (result == DialogResult.No)
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
myLog("这台洗衣机无法当作模板!", DateTime.Now);
continue;
// 用户选择了“否”
// 在这里执行相应的操作
}
@ -1751,8 +1726,11 @@ namespace HisenceYoloDetection
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);
bool isSucess= InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
if(isSucess)
{
MatchStr = false;
}
// InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop();
@ -1800,48 +1778,48 @@ namespace HisenceYoloDetection
else
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
//melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
//melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
//melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
//melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
//加上人为判断是否是NG洗衣机
DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
this.Invoke(new Action(() =>
{
OKOrNGShow.Image = NGbitmap;
}));
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt("550", 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("550", 0);//方行
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt("550", 0);//方行
////加上人为判断是否是NG洗衣机
//DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
//if (dr == DialogResult.OK)
//{
this.Invoke(new Action(() =>
{
OKOrNGShow.Image = NGbitmap;
}));
myLog("匹配成功", DateTime.Now);
}
// melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
// melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
// melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
// melsecPLCTCPDriver.WriteInt("550", 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
//{
// myLog("匹配成功", DateTime.Now);
//}
@ -1945,6 +1923,7 @@ namespace HisenceYoloDetection
{
m_sKEYENCEBar = string.Empty;
m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data);
m_sKEYENCEBar = m_sKEYENCEBar.Replace("\r", "");
// myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now);
_runHandleBefore.Set();
bBar = true;
@ -2123,7 +2102,7 @@ namespace HisenceYoloDetection
}
int i_start = 0;
private void StartDecBtn_Click(object sender, EventArgs e)
{
@ -2143,15 +2122,21 @@ namespace HisenceYoloDetection
//CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//test2");
statusButton.BackColor = Color.Green; // 设备正常运行
statusButton.Text = "运行中"; // 更新文本
// OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
meachineState = MeachineState.machine_opening;
TriggerCameral2();//光电触发拍照 根据SN获取型号 从数据库中得到块值
ReadyDetect();//相机拍照后检测线程
if (i_start == 0)
{
TriggerCameral2();//光电触发拍照 根据SN获取型号 从数据库中得到块值
ReadyDetect();//相机拍照后检测线程
i_start = 1;
}
//ThreadPost();//相机拍照后获取当日的型号
myLog("开启流程成功", DateTime.Now);
@ -3130,113 +3115,115 @@ 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 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 bool 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))
try
{
sw.WriteLine(filename + "\n");
sw.Flush();
}
// 克隆当前图像
Mat mResultCut = currentMatC.Clone();
Rect areaBlack = new Rect();
// 旋钮的位置
if (cam1Button.ResultDetails.Count == 1)
{
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++)
{
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;
//防止按钮在最右边导致定位块识别是2 + 防止定位能效贴和第3块相同将定位能效贴改成4
if (keyValueResult.Keys.Contains(blockIndex))
// 初始化日志记录
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))
{
int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex);
int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X;
int rectsYof = cam1TwoML.ResultDetails[indexof].Rect.Y;
if (rectsx > rectsxof)
{
blockIndex = "3";
}
if (rectsy > rectsYof)
{
continue;
}
sw.WriteLine(filename + "\n");
sw.Flush();
}
Rect area2 = new Rect(0, 0, 0, 0);
if (blockIndex == "2") // 根据旋钮扩大范围
// 克隆当前图像
Mat mResultCut = currentMatC.Clone();
Rect areaBlack = new Rect();
// 旋钮的位置
if (cam1Button.ResultDetails.Count == 1)
{
if ((areaBlack.X + areaBlack.Width) < (rectsx + rectsWidth))
{
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;
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);
}
Stopwatch sw = Stopwatch.StartNew();
sw.Start();
int extendHeight = 50;
rectsHeight += extendHeight;
rectsHeight = Math.Min(rectsHeight, currentMatC.Height - rectsy);
for (int i = 0; i < cam1TwoML.ResultDetails.Count; i++)
{
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;
Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight);
Mat matCut = new Mat(mResultCut, area);
// 修正区域位置,防止负数
rectsx = Math.Max(rectsx, 0);
rectsy = Math.Max(rectsy, 0);
rectsWidth = Math.Min(rectsWidth, currentMatC.Width - rectsx);
rectsHeight = Math.Min(rectsHeight, currentMatC.Height - rectsy);
// OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = paddleOcrModel.RunInference(reqcut);
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
//防止按钮在最右边导致定位块识别是2 + 防止定位能效贴和第3块相同将定位能效贴改成4
if (keyValueResult.Keys.Contains(blockIndex))
{
int indexof = keyValueResult.Keys.ToList().IndexOf(blockIndex);
int rectsxof = cam1TwoML.ResultDetails[indexof].Rect.X;
int rectsYof = cam1TwoML.ResultDetails[indexof].Rect.Y;
if (rectsx > rectsxof)
{
blockIndex = "3";
}
if (rectsy > rectsYof)
{
continue;
}
bool blockMatchI = BlockChangeFun(saveimage, blockIndex, ref matCut, ref mLCut, ref SQlxK_HisenceWord, ref xK_HisenceWord);
sw.Stop();
//myLog("插入每块板需要的时间" + sw.ElapsedMilliseconds, DateTime.Now);
}
Rect area2 = new Rect(0, 0, 0, 0);
if (blockIndex == "2") // 根据旋钮扩大范围
{
if ((areaBlack.X + areaBlack.Width) < (rectsx + rectsWidth))
{
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);
Mat matCut = new Mat(mResultCut, area);
// OCR识别裁剪图片
MLRequest reqcut = new MLRequest();
reqcut.currentMat = matCut.Clone();
MLResult mLCut = paddleOcrModel.RunInference(reqcut);
bool blockMatchI = BlockChangeFun(saveimage, blockIndex, ref matCut, ref mLCut, ref SQlxK_HisenceWord, ref xK_HisenceWord);
sw.Stop();
//myLog("插入每块板需要的时间" + sw.ElapsedMilliseconds, DateTime.Now);
keyValueResult.Add(blockIndex, blockMatchI);
}
return true;
keyValueResult.Add(blockIndex, blockMatchI);
}
//}
//catch (Exception ex)
//{
//}
catch (Exception ex)
{
return false;
}
#endif
@ -3409,7 +3396,7 @@ namespace HisenceYoloDetection
Mat SqlImg = Cv2.ImRead(PathSql);
Mat SqlBtn = GetCroppedImage(SqlImg, rectsql);
Mat BtnImg = GetCroppedImage(CutBlockMat, rectDet);//截取实时图像旋钮图片
Bitmap bitmap = MatToBitmap(BtnImg);
@ -3423,7 +3410,7 @@ namespace HisenceYoloDetection
}));
Mat matresult = CutBlockMat.Clone();
juanjiMatch = CheckDiffSciHelper.CheckDiffSci(PathSql, CutBlockMat, ref matresult, rectsql, rectDet, iswhite, "D://Hisence//Test", SN);
// juanjiMatch = true;
@ -3433,7 +3420,10 @@ namespace HisenceYoloDetection
//DisplayResult(mLcut);
//显示错误的板
// mLcut.ResultMap;
Defet_OnDetectionDone(matresult, 2);
DisplayResult(mLcut);
//显示错误的板
// mLcut.ResultMap;
Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 2);
}
else
{
@ -3806,7 +3796,23 @@ namespace HisenceYoloDetection
private void HandRuningBtn_Click(object sender, EventArgs e)
{
melsecPLCTCPDriver.WriteInt("550", 0);
using (var passwordForm = new Form2())
{
if (passwordForm.ShowDialog() == DialogResult.OK)
{
if (passwordForm.EnteredPassword == CorrectPassword)
{
// 密码正确,执行相关操作
meachineState = MeachineState.machine_closing;
melsecPLCTCPDriver.WriteInt("550", 0);
}
else
{
MessageBox.Show("密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// 软件关闭
@ -3859,6 +3865,8 @@ namespace HisenceYoloDetection
melsecPLCTCPDriver.WriteInt("550", 0);
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);
statusButton.BackColor = Color.Red; // 设备停止
statusButton.Text = "停止"; // 更新文本
}
else
{
@ -3973,5 +3981,10 @@ namespace HisenceYoloDetection
MessageBox.Show($"无法打开文件夹: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void label38_Click(object sender, EventArgs e)
{
}
}
}