diff --git a/HisenceYoloDetection/CheckDiffSciHelper.cs b/HisenceYoloDetection/CheckDiffSciHelper.cs index f200f1c..3152f28 100644 --- a/HisenceYoloDetection/CheckDiffSciHelper.cs +++ b/HisenceYoloDetection/CheckDiffSciHelper.cs @@ -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(y, x, fillColor); - } - } + // 使用 OpenCV 的 rectangle 函数进行填充 + Cv2.Rectangle(image, fillRect.TopLeft, fillRect.BottomRight, fillColor, Cv2.FILLED); return image; } + /// /// /// @@ -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; } diff --git a/HisenceYoloDetection/Form2.Designer.cs b/HisenceYoloDetection/Form2.Designer.cs index a4ed7cb..e93c71f 100644 --- a/HisenceYoloDetection/Form2.Designer.cs +++ b/HisenceYoloDetection/Form2.Designer.cs @@ -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(); diff --git a/HisenceYoloDetection/MainForm.Designer.cs b/HisenceYoloDetection/MainForm.Designer.cs index a4afd43..582e722 100644 --- a/HisenceYoloDetection/MainForm.Designer.cs +++ b/HisenceYoloDetection/MainForm.Designer.cs @@ -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; } } diff --git a/HisenceYoloDetection/MainForm.cs b/HisenceYoloDetection/MainForm.cs index bfe5c92..6aeb9dc 100644 --- a/HisenceYoloDetection/MainForm.cs +++ b/HisenceYoloDetection/MainForm.cs @@ -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); + } /// @@ -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; + + // ûѡˡ + // ִӦIJ } @@ -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 /// صĶλĽ /// /// - public void InsertSqlRunDataButton(ref Dictionary keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List strMatList, ref List strMatRefList, ref PaddleOcrModel IOcrModel) + public bool InsertSqlRunDataButton(ref Dictionary keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List strMatList, ref List 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ͬλЧij4 - 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ͬλЧij4 + 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); + } + } + } + } /// /// ر @@ -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) + { + + } } }