LB_SmartVision/CSV/CsvRecordProductData.cs
@@ -47,6 +47,26 @@ /// æ£æµç¸æº /// </summary> public string CameraInspection { get; set; } /// <summary> /// è½®èID /// </summary> public int TyreID { get; set; } /// <summary> /// å¾ååºå·ï¼1~nï¼ /// </summary> public int ImageIndex { get; set; } /// <summary> /// è½®èçº§æ£æµç»æ /// </summary> public string TyreResult { get; set; } /// <summary> /// æ¯å¼ è½®èå¾åæ° /// </summary> public int ImagesPerTyre { get; set; } } } LB_SmartVision/ProcessRun/ProcessContext.cs
@@ -6,6 +6,7 @@ using LB_VisionProcesses.Alogrithms; using LB_VisionProcesses.Cameras; using LB_VisionProcesses.Communicators; using LB_VisionProcesses.Processes; using LB_VisionProcesses.Processes.ScriptTool; using OpenCvSharp; using System.Collections.Concurrent; @@ -585,7 +586,86 @@ [Node("Halcon2Då¾å滤波", "Halcon2Då·¥å ·", "Basic", "Halcon2Då¾å滤波")] public void Halcon2Då¾å滤波(FlowNode node) { RunNodeAsync(node); } [Node("è½®è计æ°", "æ§å¶", "Logic", "è½®è计æ°èç¹")] public void è½®è计æ°(FlowNode node) { string ProcessName = node.Text; try { if (dicContext.TryGetValue(ProcessName, out IProcess obj) && obj is TyreCounterProcess counter) { UpdateInputs(counter); if (node.Break) { node.BranchIndex = "0"; node.Result = true; counter.Result = true; counter.Msg = "è½®è计æ°èç¹å·²è·³è¿"; return; } // ä»åç½®èç¹è·åæ£æµç»æï¼éè¿è¾å ¥æ å°ï¼ bool imageResult = GetPreviousResult(node); // 设置è¾å ¥ç»æ counter.InputImage = imageResult; // è¿è¡è½®èè®¡æ° if (!counter.Run()) { node.Result = false; Result &= false; Msg += $"[{ProcessName}]{counter.Msg}"; } else { node.Result = true; // 妿宿ä¸ä¸ªè½®èï¼è¾åºå®æä¿¡å· if (counter.IsTyreComplete) { Msg += $"[{ProcessName}]å®æè½®è #{counter.CurrentTyreID - 1}ï¼ç»æ: {(counter.TyreResult ? "OK" : "NG")}"; } } } else { node.Result = false; Result &= false; Msg += $"[{ProcessName}]æªæ¾å°è½®è计æ°å·¥å ·å®ä¾"; } } catch (Exception ex) { node.Result = false; Result &= false; Msg += $"[{ProcessName}]è¿è¡åçæå¤,{ex.Message}"; } } /// <summary> /// è·ååç½®èç¹çæ£æµç»æ /// </summary> private bool GetPreviousResult(FlowNode node) { try { // æ¥æ¾åç½®èç¹ var prevNode = dicContext.Values .OfType<IProcess>() .FirstOrDefault(p => p.Result == true || p.Result == false); if (prevNode != null) { return prevNode.Result; } } catch { } return true; // é»è®¤è¿åOK } #endregion LB_SmartVision/ProcessRun/ProcessRunBll.cs
@@ -875,9 +875,26 @@ double total_OK; double total_NG; /// <summary> /// è½®è级ç»è®¡ - OKè®¡æ° /// </summary> double tyre_OK; /// <summary> /// è½®è级ç»è®¡ - NGè®¡æ° /// </summary> double tyre_NG; public double total { get { return total_OK + total_NG; } } /// <summary> /// è½®èæ»æ° /// </summary> public double tyreTotal { get { return tyre_OK + tyre_NG; } } public double Rate_OK @@ -890,10 +907,37 @@ } } /// <summary> /// è½®èè¯åç /// </summary> public double TyreRate_OK { get { if (tyreTotal == 0) return 100; return (tyre_OK / tyreTotal) * 100; } } public void ClearTotal() { total_OK = 0; total_NG = 0; tyre_OK = 0; tyre_NG = 0; } /// <summary> /// æ·»å è½®èç»è®¡ /// </summary> /// <param name="isOK">è½®èæ¯å¦OK</param> public void AddTyreResult(bool isOK) { if (isOK) tyre_OK++; else tyre_NG++; } /// <summary> LB_SmartVision/SQL/RecordProductData.cs
@@ -71,5 +71,37 @@ [DisplayName("æ£æµç¸æº")] [Browsable(true)] public string CameraInspection { get; set; } /// <summary> /// è½®èID /// </summary> [Category("RecordProductData"), PropertyOrder(7)] [DisplayName("è½®èID")] [Browsable(true)] public int TyreID { get; set; } /// <summary> /// å¾ååºå·ï¼1~nï¼ /// </summary> [Category("RecordProductData"), PropertyOrder(8)] [DisplayName("å¾ååºå·")] [Browsable(true)] public int ImageIndex { get; set; } /// <summary> /// è½®èçº§æ£æµç»æ /// </summary> [Category("RecordProductData"), PropertyOrder(9)] [DisplayName("è½®èç»æ")] [Browsable(true)] public string TyreResult { get; set; } /// <summary> /// æ¯å¼ è½®èå¾åæ° /// </summary> [Category("RecordProductData"), PropertyOrder(10)] [DisplayName("è½®èå¾åæ°")] [Browsable(true)] public int ImagesPerTyre { get; set; } } } LB_VisionProcesses/BarcodeReaders/Huayray/HRBarcodeReader.cs
@@ -73,6 +73,7 @@ // åå»ºå¥æ int nRet = _camera.eidCreateDevice_Net(sn, EidCamera.EidDeviceDataType.eidDeviceDataTypeSN); if (nRet != EidCamera.eidErrorOK) return false; if (nRet != EidCamera.eidErrorOK) { _camera = null; @@ -124,11 +125,15 @@ public override bool Close() { if (!IsConnected) return true; try { if (IsConnected) { StopGrabbing(); _camera.eidCloseDevice_Net(); _camera.eidReleaseHandle_Net(); _camera?.eidCloseDevice_Net(); } // æ 论æ¯å¦è¿æ¥ï¼é½å°è¯éæ¾å¥æ @@ -144,6 +149,7 @@ _camera = null; this.IsConnected = false; this.SN = string.Empty; this.IsGrabbing = false; return true; } @@ -236,10 +242,13 @@ } } // 转æ¢å¾å (妿éè¦) // 转æ¢å¾å Bitmap bitmap = null; if (frameInfo.imageDataLen > 0 && frameInfo.imageData != IntPtr.Zero) { // è¿éç®åå¤çï¼å¦ææ¯Jpegåç´æ¥ä»å åå è½½ï¼å¦ææ¯Rawåéè½¬æ¢ // å®é 项ç®ä¸å¯æ ¹æ® frameInfo.format è¿è¡å¤ç if (frameInfo.isJpeg) { byte[] managedArray = new byte[frameInfo.imageDataLen]; LB_VisionProcesses/BarcodeReaders/IBarcodeReader.cs
@@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; namespace LB_VisionProcesses.BarcodeReaders { LB_VisionProcesses/Cameras/2DCameraForm.cs
@@ -78,7 +78,7 @@ UserPictureBox onlinePictureBox { get; set; } private System.Windows.Forms.Timer updateTimer; Total total = new Total { iImageCount = 0, iScanCount = 0 }; Total total = new Total { iImageCount = 0, iScanCount = 0, ImagesPerTyre = 1 }; DateTime startGrabtime = DateTime.Now; // å¨ææ·»å çå¢çä¸ææ¡ LB_VisionProcesses/Cameras/CameraConfig.cs
@@ -42,6 +42,11 @@ Params.Inputs.Add("è¶ æ¶æ¶é´", 1000); Params.Inputs.Add("æ¯å¦å¤±è´¥éæ°åå¾", false); // 2Dè½®è计æ°é ç½®ï¼é»è®¤ä¸º1ï¼è¡¨ç¤º3D模å¼ï¼2Dç¸æºè®¾ç½®ä¸ºnï¼ Params.Inputs.Add("ImagesPerTyre", 1); Params.Inputs.Add("å½åè½®èID", 1); Params.Inputs.Add("å½åå¾ååºå·", 0); } /// <summary> LB_VisionProcesses/Cameras/ICamera.cs
@@ -8,8 +8,45 @@ { public class Total { /// <summary> /// å¾åè®¡æ° /// </summary> public int iImageCount { get; set; } = 0; /// <summary> /// æ«æè®¡æ° /// </summary> public int iScanCount { get; set; } = 0; /// <summary> /// 宿´è½®èè®¡æ° /// </summary> public int TyreCount { get; set; } = 0; /// <summary> /// æ¯å¼ è½®èæéå¾åæ°ï¼2Dç¸æºä½¿ç¨ï¼é»è®¤1表示3Dç¸æºï¼ /// </summary> public int ImagesPerTyre { get; set; } = 1; /// <summary> /// å½åè½®èçå¾ååºå·ï¼0~ImagesPerTyre-1ï¼ /// </summary> public int CurrentImageIndex { get; set; } = 0; /// <summary> /// è½®èOKè®¡æ° /// </summary> public int TyreOK { get; set; } = 0; /// <summary> /// è½®èNGè®¡æ° /// </summary> public int TyreNG { get; set; } = 0; /// <summary> /// å½åè½®èID /// </summary> public int CurrentTyreID { get; set; } = 1; public Total() { } @@ -19,10 +56,61 @@ this.iScanCount = iScanCount; } /// <summary> /// æ·»å å¾åå¹¶æ´æ°è½®èè®¡æ° /// </summary> /// <param name="imageResult">å¾åæ£æµç»æ</param> /// <returns>æ¯å¦å®æä¸ä¸ªè½®è</returns> public bool AddImageResult(bool imageResult) { iImageCount++; CurrentImageIndex++; // æ£æ¥æ¯å¦å®æä¸ä¸ªè½®è if (CurrentImageIndex >= ImagesPerTyre) { TyreCount++; CurrentImageIndex = 0; // æ´æ°è½®èOK/NG计æ°ï¼nå¼ ä¸ä»»ä¸NGåæ´èNGï¼ if (imageResult) TyreOK++; else TyreNG++; CurrentTyreID++; return true; } return false; } /// <summary> /// è·åè½®èè¯åç /// </summary> public double TyreRateOK => TyreCount > 0 ? (TyreOK / (double)TyreCount) * 100 : 0; public void Clear() { iImageCount = 0; iScanCount = 0; TyreCount = 0; CurrentImageIndex = 0; TyreOK = 0; TyreNG = 0; CurrentTyreID = 1; } /// <summary> /// é置轮è计æ°ï¼ä¿çImagesPerTyreé ç½®ï¼ /// </summary> public void ResetTyreCount() { TyreCount = 0; CurrentImageIndex = 0; TyreOK = 0; TyreNG = 0; CurrentTyreID = 1; } } public interface ICamera : IDisposable LB_VisionProcesses/Processes/TyreCounter/TyreCounterProcess.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,413 @@ using HalconDotNet; using LB_VisionProcesses.Alogrithms; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.Processes { /// <summary> /// è½®è计æ°å·¥å · - ç¨äºæµç¨èç¹ä¸ç»è®¡è½®èæ°é /// </summary> [Process("è½®è计æ°", Category = "æ§å¶", Description = "ç¨äº2Då·¥ä½è½®è计æ°ï¼é ç½®nå¼ å¾/è½®è")] public class TyreCounterProcess : BaseProcess { #region é ç½®å±æ§ /// <summary> /// æ¯å¼ è½®èæéå¾åæ° /// </summary> public int ImagesPerTyre { get { if (Params.Inputs.ContainsKey("ImagesPerTyre")) return Convert.ToInt32(Params.Inputs["ImagesPerTyre"]); return 8; } set { Params.Inputs["ImagesPerTyre"] = value; } } /// <summary> /// å¤å®è§å /// </summary> public TyreJudgeRule JudgeRule { get { if (Params.Inputs.ContainsKey("JudgeRule")) return (TyreJudgeRule)Enum.Parse(typeof(TyreJudgeRule), Params.Inputs["JudgeRule"].ToString()); return TyreJudgeRule.AnyNG; } set { Params.Inputs["JudgeRule"] = value.ToString(); } } /// <summary> /// æ¯å¦èªå¨éç½®ï¼å®æä¸ä¸ªè½®èåèªå¨é置计æ°ï¼ /// </summary> public bool AutoReset { get { if (Params.Inputs.ContainsKey("AutoReset")) return Convert.ToBoolean(Params.Inputs["AutoReset"]); return true; } set { Params.Inputs["AutoReset"] = value; } } #endregion #region è¾åºå±æ§ /// <summary> /// å½åè½®èID /// </summary> public int CurrentTyreID { get { if (Params.Outputs.ContainsKey("CurrentTyreID")) return Convert.ToInt32(Params.Outputs["CurrentTyreID"]); return 1; } private set { Params.Outputs["CurrentTyreID"] = value; } } /// <summary> /// å½åå¾ååºå·ï¼1~nï¼ /// </summary> public int CurrentImageIndex { get { if (Params.Outputs.ContainsKey("CurrentImageIndex")) return Convert.ToInt32(Params.Outputs["CurrentImageIndex"]); return 0; } private set { Params.Outputs["CurrentImageIndex"] = value; } } /// <summary> /// æ¯å¦å®æè½®è /// </summary> public bool IsTyreComplete { get { if (Params.Outputs.ContainsKey("IsTyreComplete")) return Convert.ToBoolean(Params.Outputs["IsTyreComplete"]); return false; } private set { Params.Outputs["IsTyreComplete"] = value; } } /// <summary> /// è½®èç»æ /// </summary> public bool TyreResult { get { if (Params.Outputs.ContainsKey("TyreResult")) return Convert.ToBoolean(Params.Outputs["TyreResult"]); return false; } private set { Params.Outputs["TyreResult"] = value; } } /// <summary> /// è½®èæ»æ° /// </summary> public int TyreTotal { get { if (Params.Outputs.ContainsKey("TyreTotal")) return Convert.ToInt32(Params.Outputs["TyreTotal"]); return 0; } private set { Params.Outputs["TyreTotal"] = value; } } /// <summary> /// è½®èOKæ° /// </summary> public int TyreOK { get { if (Params.Outputs.ContainsKey("TyreOK")) return Convert.ToInt32(Params.Outputs["TyreOK"]); return 0; } private set { Params.Outputs["TyreOK"] = value; } } /// <summary> /// è½®èNGæ° /// </summary> public int TyreNG { get { if (Params.Outputs.ContainsKey("TyreNG")) return Convert.ToInt32(Params.Outputs["TyreNG"]); return 0; } private set { Params.Outputs["TyreNG"] = value; } } /// <summary> /// è¯åç /// </summary> public double TyreRateOK { get { if (Params.Outputs.ContainsKey("TyreRateOK")) return Convert.ToDouble(Params.Outputs["TyreRateOK"]); return 0; } private set { Params.Outputs["TyreRateOK"] = value; } } #endregion #region ç§æåæ®µ /// <summary> /// è½®èç»è®¡å¨å®ä¾ /// </summary> private TyreStatistics? _tyreStatistics; /// <summary> /// è¾å ¥çå¾åç»æï¼ä»åç½®èç¹è·åï¼ /// </summary> private bool _inputImageResult = true; #endregion #region æé æ¹æ³ public TyreCounterProcess() { strProcessClass = "LB_VisionProcesses.Processes.TyreCounterProcess"; _tyreStatistics = new TyreStatistics(); InitParams(); } /// <summary> /// åå§ååæ° /// </summary> private void InitParams() { // è¾å ¥åæ° if (!Params.Inputs.ContainsKey("ImagesPerTyre")) Params.Inputs.Add("ImagesPerTyre", 8); if (!Params.Inputs.ContainsKey("JudgeRule")) Params.Inputs.Add("JudgeRule", TyreJudgeRule.AnyNG.ToString()); if (!Params.Inputs.ContainsKey("AutoReset")) Params.Inputs.Add("AutoReset", true); // è¾åºåæ° if (!Params.Outputs.ContainsKey("CurrentTyreID")) Params.Outputs.Add("CurrentTyreID", 1); if (!Params.Outputs.ContainsKey("CurrentImageIndex")) Params.Outputs.Add("CurrentImageIndex", 0); if (!Params.Outputs.ContainsKey("IsTyreComplete")) Params.Outputs.Add("IsTyreComplete", false); if (!Params.Outputs.ContainsKey("TyreResult")) Params.Outputs.Add("TyreResult", false); if (!Params.Outputs.ContainsKey("TyreTotal")) Params.Outputs.Add("TyreTotal", 0); if (!Params.Outputs.ContainsKey("TyreOK")) Params.Outputs.Add("TyreOK", 0); if (!Params.Outputs.ContainsKey("TyreNG")) Params.Outputs.Add("TyreNG", 0); if (!Params.Outputs.ContainsKey("TyreRateOK")) Params.Outputs.Add("TyreRateOK", 0.0); } #endregion #region æ ¸å¿æ¹æ³ /// <summary> /// è¿è¡è½®è计æ°é»è¾ /// </summary> public override bool Run() { DateTime startTime = DateTime.Now; try { // è·åè¾å ¥ç»æï¼ä»åç½®èç¹çResultåæ°ï¼ GetInputResult(); // æ´æ°ç»è®¡å¨é ç½® _tyreStatistics.ImagesPerTyre = ImagesPerTyre; _tyreStatistics.JudgeRule = JudgeRule; // æ·»å å¾åç»æ var result = _tyreStatistics.AddImageResult(_inputImageResult); // æ´æ°è¾åºåæ° UpdateOutputs(result); // è®¾ç½®ç»æ Result = true; Msg = result.Message; RunTime = (DateTime.Now - startTime).TotalMilliseconds; return true; } catch (Exception ex) { Result = false; Msg = $"è½®è计æ°è¿è¡å¤±è´¥: {ex.Message}"; RunTime = (DateTime.Now - startTime).TotalMilliseconds; return false; } } /// <summary> /// è·åè¾å ¥ç»æï¼ä»åç½®èç¹ä¼ éçResultï¼ /// </summary> private void GetInputResult() { // 妿InputImageæ¯boolç±»åï¼è¯´æåç½®èç¹ä¼ éäºç»æ if (InputImage is bool boolResult) { _inputImageResult = boolResult; } else { // é»è®¤è®¤ä¸ºOK _inputImageResult = true; } } /// <summary> /// æ´æ°è¾åºåæ° /// </summary> private void UpdateOutputs(TyreCountResult result) { CurrentTyreID = result.TyreID > 0 ? result.TyreID : _tyreStatistics.CurrentTyreID; CurrentImageIndex = result.CurrentImageIndex; IsTyreComplete = result.IsTyreComplete; TyreResult = result.TyreResult; TyreTotal = _tyreStatistics.TyreTotal; TyreOK = _tyreStatistics.TyreOK; TyreNG = _tyreStatistics.TyreNG; TyreRateOK = _tyreStatistics.TyreRateOK; } /// <summary> /// åå§åè¿è¡åæ° /// </summary> public override void InitRunParams() { base.InitRunParams(); _inputImageResult = true; } /// <summary> /// é置轮èè®¡æ° /// </summary> public void ResetTyreCount() { _tyreStatistics?.Reset(); UpdateOutputs(new TyreCountResult()); } /// <summary> /// è·åç»è®¡ä¿¡æ¯ /// </summary> public string GetStatisticsInfo() { return _tyreStatistics?.GetStatisticsInfo() ?? "ç»è®¡å¨æªåå§å"; } /// <summary> /// è·åè¿åº¦ä¿¡æ¯ /// </summary> public string GetProgressInfo() { return _tyreStatistics?.GetProgressInfo() ?? "ç»è®¡å¨æªåå§å"; } #endregion #region éåæ¹æ³ public override bool Load(string fullPath = null) { bool result = base.Load(fullPath); if (result) { // å è½½é ç½®åéæ°åå§åç»è®¡å¨ _tyreStatistics = new TyreStatistics(ImagesPerTyre, JudgeRule); } return result; } public override bool Save(string filePath = null) { return base.Save(filePath); } public override object Clone() { TyreCounterProcess clone = (TyreCounterProcess)MemberwiseClone(); clone._tyreStatistics = new TyreStatistics(ImagesPerTyre, JudgeRule); return clone; } public override void Dispose() { _tyreStatistics = null; base.Dispose(); } #endregion } } LB_VisionProcesses/Processes/TyreCounter/TyreCounterProcessEdit.Designer.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,567 @@ namespace LB_VisionProcesses.Processes { partial class TyreCounterProcessEdit { /// <summary> /// å¿ éç设计å¨åéã /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// æ¸ çæææ£å¨ä½¿ç¨çèµæºã /// </summary> /// <param name="disposing">妿åºéæ¾æç®¡èµæºï¼ä¸º trueï¼å¦å为 falseã</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region ç»ä»¶è®¾è®¡å¨çæç代ç /// <summary> /// è®¾è®¡å¨æ¯ææéçæ¹æ³ - ä¸è¦ä¿®æ¹ /// 使ç¨ä»£ç ç¼è¾å¨ä¿®æ¹æ¤æ¹æ³çå 容ã /// </summary> private void InitializeComponent() { splitContainer1 = new SplitContainer(); groupBoxInputs = new GroupBox(); dataGridInputs = new DataGridView(); groupBoxConfig = new GroupBox(); tableLayoutPanelConfig = new TableLayoutPanel(); lblImagesPerTyre = new Label(); numericUpDownImagesPerTyre = new NumericUpDown(); lblJudgeRule = new Label(); comboBoxJudgeRule = new ComboBox(); checkBoxAutoReset = new CheckBox(); groupBoxStatistics = new GroupBox(); tableLayoutPanelStats = new TableLayoutPanel(); lblCurrentTyreID = new Label(); txtCurrentTyreID = new TextBox(); lblCurrentImageIndex = new Label(); txtCurrentImageIndex = new TextBox(); lblTyreTotal = new Label(); txtTyreTotal = new TextBox(); lblTyreOK = new Label(); txtTyreOK = new TextBox(); lblTyreNG = new Label(); txtTyreNG = new TextBox(); lblTyreRateOK = new Label(); txtTyreRateOK = new TextBox(); groupBoxOutputs = new GroupBox(); dataGridOutputs = new DataGridView(); topToolStrip = new ToolStrip(); btnRun = new ToolStripButton(); btnSave = new ToolStripButton(); btnReset = new ToolStripButton(); statusStrip = new StatusStrip(); lblResult = new ToolStripStatusLabel(); lblMsg = new ToolStripStatusLabel(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); splitContainer1.Panel1.SuspendLayout(); splitContainer1.Panel2.SuspendLayout(); splitContainer1.SuspendLayout(); groupBoxInputs.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridInputs).BeginInit(); groupBoxConfig.SuspendLayout(); tableLayoutPanelConfig.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownImagesPerTyre).BeginInit(); groupBoxStatistics.SuspendLayout(); tableLayoutPanelStats.SuspendLayout(); groupBoxOutputs.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridOutputs).BeginInit(); topToolStrip.SuspendLayout(); statusStrip.SuspendLayout(); SuspendLayout(); // // splitContainer1 // splitContainer1.BackColor = Color.FromArgb(32, 41, 50); splitContainer1.Dock = DockStyle.Fill; splitContainer1.Location = new Point(0, 31); splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // splitContainer1.Panel1.Controls.Add(groupBoxInputs); // // splitContainer1.Panel2 // splitContainer1.Panel2.Controls.Add(groupBoxOutputs); splitContainer1.Size = new Size(884, 458); splitContainer1.SplitterDistance = 294; splitContainer1.TabIndex = 0; // // groupBoxInputs // groupBoxInputs.BackColor = Color.FromArgb(32, 41, 50); groupBoxInputs.Controls.Add(dataGridInputs); groupBoxInputs.Dock = DockStyle.Fill; groupBoxInputs.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); groupBoxInputs.ForeColor = SystemColors.Control; groupBoxInputs.Location = new Point(0, 0); groupBoxInputs.Name = "groupBoxInputs"; groupBoxInputs.Size = new Size(294, 458); groupBoxInputs.TabIndex = 0; groupBoxInputs.TabStop = false; groupBoxInputs.Text = "è¾å ¥åæ°"; // // dataGridInputs // dataGridInputs.BackgroundColor = Color.FromArgb(32, 46, 50); dataGridInputs.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridInputs.Dock = DockStyle.Fill; dataGridInputs.GridColor = SystemColors.Control; dataGridInputs.Location = new Point(3, 24); dataGridInputs.Name = "dataGridInputs"; dataGridInputs.Size = new Size(288, 431); dataGridInputs.TabIndex = 0; // // groupBoxConfig // groupBoxConfig.BackColor = Color.FromArgb(32, 41, 50); groupBoxConfig.Controls.Add(tableLayoutPanelConfig); groupBoxConfig.Dock = DockStyle.Top; groupBoxConfig.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); groupBoxConfig.ForeColor = SystemColors.Control; groupBoxConfig.Location = new Point(0, 0); groupBoxConfig.Name = "groupBoxConfig"; groupBoxConfig.Size = new Size(586, 180); groupBoxConfig.TabIndex = 1; groupBoxConfig.TabStop = false; groupBoxConfig.Text = "é ç½®"; // // tableLayoutPanelConfig // tableLayoutPanelConfig.ColumnCount = 2; tableLayoutPanelConfig.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F)); tableLayoutPanelConfig.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tableLayoutPanelConfig.Controls.Add(lblImagesPerTyre, 0, 0); tableLayoutPanelConfig.Controls.Add(numericUpDownImagesPerTyre, 1, 0); tableLayoutPanelConfig.Controls.Add(lblJudgeRule, 0, 1); tableLayoutPanelConfig.Controls.Add(comboBoxJudgeRule, 1, 1); tableLayoutPanelConfig.Controls.Add(checkBoxAutoReset, 1, 2); tableLayoutPanelConfig.Dock = DockStyle.Fill; tableLayoutPanelConfig.Location = new Point(3, 24); tableLayoutPanelConfig.Name = "tableLayoutPanelConfig"; tableLayoutPanelConfig.RowCount = 3; tableLayoutPanelConfig.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); tableLayoutPanelConfig.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); tableLayoutPanelConfig.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F)); tableLayoutPanelConfig.Size = new Size(580, 153); tableLayoutPanelConfig.TabIndex = 0; // // lblImagesPerTyre // lblImagesPerTyre.AutoSize = true; lblImagesPerTyre.Dock = DockStyle.Fill; lblImagesPerTyre.Location = new Point(3, 0); lblImagesPerTyre.Name = "lblImagesPerTyre"; lblImagesPerTyre.Size = new Size(144, 40); lblImagesPerTyre.TabIndex = 0; lblImagesPerTyre.Text = "æ¯å¼ è½®èå¾åæ°:"; lblImagesPerTyre.TextAlign = ContentAlignment.MiddleLeft; // // numericUpDownImagesPerTyre // numericUpDownImagesPerTyre.Location = new Point(153, 3); numericUpDownImagesPerTyre.Maximum = new decimal(new int[] { 64, 0, 0, 0 }); numericUpDownImagesPerTyre.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); numericUpDownImagesPerTyre.Name = "numericUpDownImagesPerTyre"; numericUpDownImagesPerTyre.Size = new Size(100, 29); numericUpDownImagesPerTyre.TabIndex = 1; numericUpDownImagesPerTyre.Value = new decimal(new int[] { 8, 0, 0, 0 }); // // lblJudgeRule // lblJudgeRule.AutoSize = true; lblJudgeRule.Dock = DockStyle.Fill; lblJudgeRule.Location = new Point(3, 40); lblJudgeRule.Name = "lblJudgeRule"; lblJudgeRule.Size = new Size(144, 40); lblJudgeRule.TabIndex = 2; lblJudgeRule.Text = "å¤å®è§å:"; lblJudgeRule.TextAlign = ContentAlignment.MiddleLeft; // // comboBoxJudgeRule // comboBoxJudgeRule.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxJudgeRule.FormattingEnabled = true; comboBoxJudgeRule.Items.AddRange(new object[] { "AnyNG", "AllOK", "MajorityVote" }); comboBoxJudgeRule.Location = new Point(153, 43); comboBoxJudgeRule.Name = "comboBoxJudgeRule"; comboBoxJudgeRule.Size = new Size(160, 29); comboBoxJudgeRule.TabIndex = 3; // // checkBoxAutoReset // checkBoxAutoReset.AutoSize = true; checkBoxAutoReset.Checked = true; checkBoxAutoReset.CheckState = CheckState.Checked; checkBoxAutoReset.Location = new Point(153, 83); checkBoxAutoReset.Name = "checkBoxAutoReset"; checkBoxAutoReset.Size = new Size(161, 25); checkBoxAutoReset.TabIndex = 4; checkBoxAutoReset.Text = "å®æè½®èèªå¨éç½®"; checkBoxAutoReset.UseVisualStyleBackColor = true; // // groupBoxStatistics // groupBoxStatistics.BackColor = Color.FromArgb(32, 41, 50); groupBoxStatistics.Controls.Add(tableLayoutPanelStats); groupBoxStatistics.Dock = DockStyle.Fill; groupBoxStatistics.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); groupBoxStatistics.ForeColor = SystemColors.Control; groupBoxStatistics.Location = new Point(0, 180); groupBoxStatistics.Name = "groupBoxStatistics"; groupBoxStatistics.Size = new Size(586, 278); groupBoxStatistics.TabIndex = 2; groupBoxStatistics.TabStop = false; groupBoxStatistics.Text = "ç»è®¡ä¿¡æ¯"; // // tableLayoutPanelStats // tableLayoutPanelStats.ColumnCount = 2; tableLayoutPanelStats.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F)); tableLayoutPanelStats.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tableLayoutPanelStats.Controls.Add(lblCurrentTyreID, 0, 0); tableLayoutPanelStats.Controls.Add(txtCurrentTyreID, 1, 0); tableLayoutPanelStats.Controls.Add(lblCurrentImageIndex, 0, 1); tableLayoutPanelStats.Controls.Add(txtCurrentImageIndex, 1, 1); tableLayoutPanelStats.Controls.Add(lblTyreTotal, 0, 2); tableLayoutPanelStats.Controls.Add(txtTyreTotal, 1, 2); tableLayoutPanelStats.Controls.Add(lblTyreOK, 0, 3); tableLayoutPanelStats.Controls.Add(txtTyreOK, 1, 3); tableLayoutPanelStats.Controls.Add(lblTyreNG, 0, 4); tableLayoutPanelStats.Controls.Add(txtTyreNG, 1, 4); tableLayoutPanelStats.Controls.Add(lblTyreRateOK, 0, 5); tableLayoutPanelStats.Controls.Add(txtTyreRateOK, 1, 5); tableLayoutPanelStats.Dock = DockStyle.Fill; tableLayoutPanelStats.Location = new Point(3, 24); tableLayoutPanelStats.Name = "tableLayoutPanelStats"; tableLayoutPanelStats.RowCount = 6; tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.RowStyles.Add(new RowStyle(SizeType.Absolute, 35F)); tableLayoutPanelStats.Size = new Size(580, 251); tableLayoutPanelStats.TabIndex = 0; // // lblCurrentTyreID // lblCurrentTyreID.AutoSize = true; lblCurrentTyreID.Dock = DockStyle.Fill; lblCurrentTyreID.Location = new Point(3, 0); lblCurrentTyreID.Name = "lblCurrentTyreID"; lblCurrentTyreID.Size = new Size(144, 35); lblCurrentTyreID.TabIndex = 0; lblCurrentTyreID.Text = "å½åè½®èID:"; lblCurrentTyreID.TextAlign = ContentAlignment.MiddleLeft; // // txtCurrentTyreID // txtCurrentTyreID.BackColor = Color.FromArgb(32, 46, 50); txtCurrentTyreID.BorderStyle = BorderStyle.FixedSingle; txtCurrentTyreID.ForeColor = SystemColors.Control; txtCurrentTyreID.Location = new Point(153, 3); txtCurrentTyreID.Name = "txtCurrentTyreID"; txtCurrentTyreID.ReadOnly = true; txtCurrentTyreID.Size = new Size(100, 29); txtCurrentTyreID.TabIndex = 1; txtCurrentTyreID.Text = "1"; // // lblCurrentImageIndex // lblCurrentImageIndex.AutoSize = true; lblCurrentImageIndex.Dock = DockStyle.Fill; lblCurrentImageIndex.Location = new Point(3, 35); lblCurrentImageIndex.Name = "lblCurrentImageIndex"; lblCurrentImageIndex.Size = new Size(144, 35); lblCurrentImageIndex.TabIndex = 2; lblCurrentImageIndex.Text = "å½åå¾ååºå·:"; lblCurrentImageIndex.TextAlign = ContentAlignment.MiddleLeft; // // txtCurrentImageIndex // txtCurrentImageIndex.BackColor = Color.FromArgb(32, 46, 50); txtCurrentImageIndex.BorderStyle = BorderStyle.FixedSingle; txtCurrentImageIndex.ForeColor = SystemColors.Control; txtCurrentImageIndex.Location = new Point(153, 38); txtCurrentImageIndex.Name = "txtCurrentImageIndex"; txtCurrentImageIndex.ReadOnly = true; txtCurrentImageIndex.Size = new Size(100, 29); txtCurrentImageIndex.TabIndex = 3; txtCurrentImageIndex.Text = "0/8"; // // lblTyreTotal // lblTyreTotal.AutoSize = true; lblTyreTotal.Dock = DockStyle.Fill; lblTyreTotal.Location = new Point(3, 70); lblTyreTotal.Name = "lblTyreTotal"; lblTyreTotal.Size = new Size(144, 35); lblTyreTotal.TabIndex = 4; lblTyreTotal.Text = "è½®èæ»æ°:"; lblTyreTotal.TextAlign = ContentAlignment.MiddleLeft; // // txtTyreTotal // txtTyreTotal.BackColor = Color.FromArgb(32, 46, 50); txtTyreTotal.BorderStyle = BorderStyle.FixedSingle; txtTyreTotal.ForeColor = SystemColors.Control; txtTyreTotal.Location = new Point(153, 73); txtTyreTotal.Name = "txtTyreTotal"; txtTyreTotal.ReadOnly = true; txtTyreTotal.Size = new Size(100, 29); txtTyreTotal.TabIndex = 5; txtTyreTotal.Text = "0"; // // lblTyreOK // lblTyreOK.AutoSize = true; lblTyreOK.Dock = DockStyle.Fill; lblTyreOK.ForeColor = Color.LightGreen; lblTyreOK.Location = new Point(3, 105); lblTyreOK.Name = "lblTyreOK"; lblTyreOK.Size = new Size(144, 35); lblTyreOK.TabIndex = 6; lblTyreOK.Text = "è½®èOK:"; lblTyreOK.TextAlign = ContentAlignment.MiddleLeft; // // txtTyreOK // txtTyreOK.BackColor = Color.FromArgb(32, 46, 50); txtTyreOK.BorderStyle = BorderStyle.FixedSingle; txtTyreOK.ForeColor = Color.LightGreen; txtTyreOK.Location = new Point(153, 108); txtTyreOK.Name = "txtTyreOK"; txtTyreOK.ReadOnly = true; txtTyreOK.Size = new Size(100, 29); txtTyreOK.TabIndex = 7; txtTyreOK.Text = "0"; // // lblTyreNG // lblTyreNG.AutoSize = true; lblTyreNG.Dock = DockStyle.Fill; lblTyreNG.ForeColor = Color.LightCoral; lblTyreNG.Location = new Point(3, 140); lblTyreNG.Name = "lblTyreNG"; lblTyreNG.Size = new Size(144, 35); lblTyreNG.TabIndex = 8; lblTyreNG.Text = "è½®èNG:"; lblTyreNG.TextAlign = ContentAlignment.MiddleLeft; // // txtTyreNG // txtTyreNG.BackColor = Color.FromArgb(32, 46, 50); txtTyreNG.BorderStyle = BorderStyle.FixedSingle; txtTyreNG.ForeColor = Color.LightCoral; txtTyreNG.Location = new Point(153, 143); txtTyreNG.Name = "txtTyreNG"; txtTyreNG.ReadOnly = true; txtTyreNG.Size = new Size(100, 29); txtTyreNG.TabIndex = 9; txtTyreNG.Text = "0"; // // lblTyreRateOK // lblTyreRateOK.AutoSize = true; lblTyreRateOK.Dock = DockStyle.Fill; lblTyreRateOK.Location = new Point(3, 175); lblTyreRateOK.Name = "lblTyreRateOK"; lblTyreRateOK.Size = new Size(144, 35); lblTyreRateOK.TabIndex = 10; lblTyreRateOK.Text = "è¯åç:"; lblTyreRateOK.TextAlign = ContentAlignment.MiddleLeft; // // txtTyreRateOK // txtTyreRateOK.BackColor = Color.FromArgb(32, 46, 50); txtTyreRateOK.BorderStyle = BorderStyle.FixedSingle; txtTyreRateOK.ForeColor = SystemColors.Control; txtTyreRateOK.Location = new Point(153, 178); txtTyreRateOK.Name = "txtTyreRateOK"; txtTyreRateOK.ReadOnly = true; txtTyreRateOK.Size = new Size(100, 29); txtTyreRateOK.TabIndex = 11; txtTyreRateOK.Text = "0.00%"; // // groupBoxOutputs // groupBoxOutputs.BackColor = Color.FromArgb(32, 41, 50); groupBoxOutputs.Controls.Add(groupBoxStatistics); groupBoxOutputs.Controls.Add(groupBoxConfig); groupBoxOutputs.Dock = DockStyle.Fill; groupBoxOutputs.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); groupBoxOutputs.ForeColor = SystemColors.Control; groupBoxOutputs.Location = new Point(0, 0); groupBoxOutputs.Name = "groupBoxOutputs"; groupBoxOutputs.Size = new Size(586, 458); groupBoxOutputs.TabIndex = 0; groupBoxOutputs.TabStop = false; groupBoxOutputs.Text = "è¾åºä¸é ç½®"; // // dataGridOutputs // dataGridOutputs.BackgroundColor = Color.FromArgb(32, 46, 50); dataGridOutputs.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridOutputs.Dock = DockStyle.Fill; dataGridOutputs.GridColor = SystemColors.Control; dataGridOutputs.Location = new Point(3, 24); dataGridOutputs.Name = "dataGridOutputs"; dataGridOutputs.Size = new Size(580, 431); dataGridOutputs.TabIndex = 0; // // topToolStrip // topToolStrip.BackColor = Color.FromArgb(32, 41, 50); topToolStrip.GripStyle = ToolStripGripStyle.Hidden; topToolStrip.Items.AddRange(new ToolStripItem[] { btnRun, btnSave, btnReset }); topToolStrip.Location = new Point(0, 0); topToolStrip.Name = "topToolStrip"; topToolStrip.Size = new Size(884, 31); topToolStrip.TabIndex = 1; topToolStrip.Text = "toolStrip1"; // // btnRun // btnRun.DisplayStyle = ToolStripItemDisplayStyle.Text; btnRun.Font = new Font("Microsoft YaHei UI", 10F, FontStyle.Regular, GraphicsUnit.Point, 134); btnRun.ForeColor = SystemColors.Control; btnRun.ImageTransparentColor = Color.Magenta; btnRun.Name = "btnRun"; btnRun.Size = new Size(41, 28); btnRun.Text = "è¿è¡"; btnRun.Click += btnRun_Click; // // btnSave // btnSave.DisplayStyle = ToolStripItemDisplayStyle.Text; btnSave.Font = new Font("Microsoft YaHei UI", 10F, FontStyle.Regular, GraphicsUnit.Point, 134); btnSave.ForeColor = SystemColors.Control; btnSave.ImageTransparentColor = Color.Magenta; btnSave.Name = "btnSave"; btnSave.Size = new Size(41, 28); btnSave.Text = "ä¿å"; btnSave.Click += btnSave_Click; // // btnReset // btnReset.DisplayStyle = ToolStripItemDisplayStyle.Text; btnReset.Font = new Font("Microsoft YaHei UI", 10F, FontStyle.Regular, GraphicsUnit.Point, 134); btnReset.ForeColor = SystemColors.Control; btnReset.ImageTransparentColor = Color.Magenta; btnReset.Name = "btnReset"; btnReset.Size = new Size(73, 28); btnReset.Text = "é置计æ°"; btnReset.Click += btnReset_Click; // // statusStrip // statusStrip.BackColor = Color.FromArgb(32, 41, 50); statusStrip.Items.AddRange(new ToolStripItem[] { lblResult, lblMsg }); statusStrip.Location = new Point(0, 489); statusStrip.Name = "statusStrip"; statusStrip.Size = new Size(884, 30); statusStrip.TabIndex = 2; statusStrip.Text = "statusStrip1"; // // lblResult // lblResult.AutoSize = false; lblResult.BackColor = Color.FromArgb(32, 41, 50); lblResult.Font = new Font("Microsoft YaHei UI", 10F, FontStyle.Regular, GraphicsUnit.Point, 134); lblResult.ForeColor = SystemColors.Control; lblResult.Name = "lblResult"; lblResult.Size = new Size(100, 25); lblResult.Text = "ç»æ: --"; // // lblMsg // lblMsg.BackColor = Color.FromArgb(32, 41, 50); lblMsg.Font = new Font("Microsoft YaHei UI", 10F, FontStyle.Regular, GraphicsUnit.Point, 134); lblMsg.ForeColor = SystemColors.Control; lblMsg.Name = "lblMsg"; lblMsg.Size = new Size(769, 25); lblMsg.Spring = true; lblMsg.Text = "就绪"; lblMsg.TextAlign = ContentAlignment.MiddleLeft; // // TyreCounterProcessEdit // AutoScaleDimensions = new SizeF(9F, 20F); AutoScaleMode = AutoScaleMode.Font; BackColor = Color.FromArgb(32, 41, 50); Controls.Add(splitContainer1); Controls.Add(topToolStrip); Controls.Add(statusStrip); Name = "TyreCounterProcessEdit"; Size = new Size(884, 519); Load += TyreCounterProcessEdit_Load; splitContainer1.Panel1.ResumeLayout(false); splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); splitContainer1.ResumeLayout(false); groupBoxInputs.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridInputs).EndInit(); groupBoxConfig.ResumeLayout(false); tableLayoutPanelConfig.ResumeLayout(false); tableLayoutPanelConfig.PerformLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownImagesPerTyre).EndInit(); groupBoxStatistics.ResumeLayout(false); tableLayoutPanelStats.ResumeLayout(false); tableLayoutPanelStats.PerformLayout(); groupBoxOutputs.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridOutputs).EndInit(); topToolStrip.ResumeLayout(false); topToolStrip.PerformLayout(); statusStrip.ResumeLayout(false); statusStrip.PerformLayout(); ResumeLayout(false); statusStrip.PerformLayout(); } #endregion private SplitContainer splitContainer1; private GroupBox groupBoxInputs; private DataGridView dataGridInputs; private GroupBox groupBoxOutputs; private DataGridView dataGridOutputs; private ToolStrip topToolStrip; private ToolStripButton btnRun; private ToolStripButton btnSave; private ToolStripButton btnReset; private StatusStrip statusStrip; private ToolStripStatusLabel lblResult; private ToolStripStatusLabel lblMsg; private GroupBox groupBoxConfig; private TableLayoutPanel tableLayoutPanelConfig; private Label lblImagesPerTyre; private NumericUpDown numericUpDownImagesPerTyre; private Label lblJudgeRule; private ComboBox comboBoxJudgeRule; private CheckBox checkBoxAutoReset; private GroupBox groupBoxStatistics; private TableLayoutPanel tableLayoutPanelStats; private Label lblCurrentTyreID; private TextBox txtCurrentTyreID; private Label lblCurrentImageIndex; private TextBox txtCurrentImageIndex; private Label lblTyreTotal; private TextBox txtTyreTotal; private Label lblTyreOK; private TextBox txtTyreOK; private Label lblTyreNG; private TextBox txtTyreNG; private Label lblTyreRateOK; private TextBox txtTyreRateOK; } } LB_VisionProcesses/Processes/TyreCounter/TyreCounterProcessEdit.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,161 @@ using LB_VisionProcesses.Alogrithms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace LB_VisionProcesses.Processes { /// <summary> /// è½®è计æ°å·¥å ·ç¼è¾å¨ /// </summary> public partial class TyreCounterProcessEdit : TAlgorithmEdit { DataTable DataTableInputs = new DataTable(); DataTable DataTableOutputs = new DataTable(); public TyreCounterProcessEdit(TyreCounterProcess subject = null) { InitializeComponent(); if (subject == null) subject = new TyreCounterProcess(); this.Subject = subject; } private void TyreCounterProcessEdit_Load(object sender, EventArgs e) { LoadParas(); } /// <summary> /// å è½½åæ° /// </summary> public override void LoadParas() { if (Subject is TyreCounterProcess counter) { // å è½½é ç½®åæ° numericUpDownImagesPerTyre.Value = counter.ImagesPerTyre; comboBoxJudgeRule.SelectedItem = counter.JudgeRule.ToString(); checkBoxAutoReset.Checked = counter.AutoReset; // å è½½ç»è®¡ä¿¡æ¯ UpdateStatistics(); // ç»å®è¾å ¥åæ° DataTableInputs.Columns.Add("Key", typeof(string)); DataTableInputs.Columns.Add("Value", typeof(object)); DataTableInputs.Rows.Clear(); var inputs = new Dictionary<string, object> { { "ImagesPerTyre", counter.ImagesPerTyre }, { "JudgeRule", counter.JudgeRule.ToString() }, { "AutoReset", counter.AutoReset } }; foreach (var item in inputs) DataTableInputs.Rows.Add(item.Key, item.Value); dataGridInputs.DataSource = DataTableInputs; // ç»å®è¾åºåæ° DataTableOutputs.Columns.Add("Key", typeof(string)); DataTableOutputs.Columns.Add("Value", typeof(object)); DataTableOutputs.Rows.Clear(); var outputs = new Dictionary<string, object> { { "CurrentTyreID", counter.CurrentTyreID }, { "CurrentImageIndex", counter.CurrentImageIndex }, { "IsTyreComplete", counter.IsTyreComplete }, { "TyreResult", counter.TyreResult }, { "TyreTotal", counter.TyreTotal }, { "TyreOK", counter.TyreOK }, { "TyreNG", counter.TyreNG }, { "TyreRateOK", counter.TyreRateOK } }; foreach (var item in outputs) DataTableOutputs.Rows.Add(item.Key, item.Value); dataGridOutputs.DataSource = DataTableOutputs; // è®¾ç½®ç¶ææ lblResult.Text = $"ç»æ: {(counter.Result ? "OK" : "NG")}"; lblResult.ForeColor = counter.Result ? Color.LightGreen : Color.LightCoral; lblMsg.Text = counter.Msg; } } /// <summary> /// æ´æ°ç»è®¡ä¿¡æ¯æ¾ç¤º /// </summary> private void UpdateStatistics() { if (Subject is TyreCounterProcess counter) { txtCurrentTyreID.Text = counter.CurrentTyreID.ToString(); txtCurrentImageIndex.Text = $"{counter.CurrentImageIndex}/{counter.ImagesPerTyre}"; txtTyreTotal.Text = counter.TyreTotal.ToString(); txtTyreOK.Text = counter.TyreOK.ToString(); txtTyreNG.Text = counter.TyreNG.ToString(); txtTyreRateOK.Text = $"{counter.TyreRateOK:F2}%"; } } /// <summary> /// æ´æ°è¾å ¥åæ° /// </summary> public override void UpdataInputs() { if (Subject is TyreCounterProcess counter) { counter.ImagesPerTyre = (int)numericUpDownImagesPerTyre.Value; counter.JudgeRule = (TyreJudgeRule)Enum.Parse(typeof(TyreJudgeRule), comboBoxJudgeRule.SelectedItem?.ToString() ?? "AnyNG"); counter.AutoReset = checkBoxAutoReset.Checked; // æ´æ°è¾å ¥åæ°è¡¨ Subject.Params.Inputs["ImagesPerTyre"] = counter.ImagesPerTyre; Subject.Params.Inputs["JudgeRule"] = counter.JudgeRule.ToString(); Subject.Params.Inputs["AutoReset"] = counter.AutoReset; } } private void btnSave_Click(object sender, EventArgs e) { UpdataInputs(); lblMsg.Text = "åæ°å·²ä¿å"; lblMsg.ForeColor = Color.LightGreen; } private void btnReset_Click(object sender, EventArgs e) { if (Subject is TyreCounterProcess counter) { counter.ResetTyreCount(); UpdateStatistics(); LoadParas(); lblMsg.Text = "计æ°å¨å·²éç½®"; lblMsg.ForeColor = Color.LightGreen; } } private void btnRun_Click(object sender, EventArgs e) { UpdataInputs(); Subject.Run(); UpdateStatistics(); LoadParas(); lblResult.Text = $"ç»æ: {(Subject.Result ? "OK" : "NG")}"; lblResult.ForeColor = Subject.Result ? Color.LightGreen : Color.LightCoral; lblMsg.Text = Subject.Msg; } } } LB_VisionProcesses/Processes/TyreCounter/TyreStatistics.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,266 @@ using System; using System.Collections.Generic; using System.Linq; namespace LB_VisionProcesses.Processes { /// <summary> /// è½®èå¤å®è§å /// </summary> public enum TyreJudgeRule { /// <summary> /// ä»»ä¸NGåæ´èNG /// </summary> AnyNG, /// <summary> /// å ¨é¨OKææ´èOK /// </summary> AllOK, /// <summary> /// 夿°è¡¨å³ï¼è¶ è¿åæ°OKåOKï¼ /// </summary> MajorityVote } /// <summary> /// è½®è计æ°ç»æ /// </summary> public class TyreCountResult { /// <summary> /// æ¯å¦å®æä¸ä¸ªè½®è /// </summary> public bool IsTyreComplete { get; set; } /// <summary> /// è½®èID /// </summary> public int TyreID { get; set; } /// <summary> /// è½®èæ´ä½ç»æ /// </summary> public bool TyreResult { get; set; } /// <summary> /// åå¾åç»æå表 /// </summary> public List<bool> ImageResults { get; set; } = new List<bool>(); /// <summary> /// å½åå¾ååºå·ï¼1~nï¼ /// </summary> public int CurrentImageIndex { get; set; } /// <summary> /// æ¶æ¯ /// </summary> public string Message { get; set; } } /// <summary> /// è½®èç»è®¡å¨ - ç¨äºç®¡çè½®è级å«ç计æ°åç»è®¡ /// </summary> public class TyreStatistics { #region é ç½®åæ° /// <summary> /// æ¯å¼ è½®èæéå¾åæ°ï¼é»è®¤8å¼ ï¼ /// </summary> public int ImagesPerTyre { get; set; } = 8; /// <summary> /// å¤å®è§å /// </summary> public TyreJudgeRule JudgeRule { get; set; } = TyreJudgeRule.AnyNG; #endregion #region ç»è®¡æ°æ® /// <summary> /// è½®èæ»æ° /// </summary> public int TyreTotal => TyreOK + TyreNG; /// <summary> /// è½®èOKè®¡æ° /// </summary> public int TyreOK { get; set; } /// <summary> /// è½®èNGè®¡æ° /// </summary> public int TyreNG { get; set; } /// <summary> /// å½åè½®èIDï¼ä»1å¼å§ï¼ /// </summary> public int CurrentTyreID { get; set; } = 1; /// <summary> /// å½åè½®èçå¾ååºå·ï¼0~ImagesPerTyre-1ï¼ /// </summary> public int CurrentImageIndex { get; set; } = 0; /// <summary> /// å½åè½®èçåå¾åç»æ /// </summary> public List<bool> CurrentTyreResults { get; set; } = new List<bool>(); /// <summary> /// å½åè½®èçåå¾åSN /// </summary> public List<string> CurrentTyreImageSNs { get; set; } = new List<string>(); /// <summary> /// è½®èè¯åç /// </summary> public double TyreRateOK => TyreTotal > 0 ? (TyreOK / (double)TyreTotal) * 100 : 0; #endregion #region æé æ¹æ³ public TyreStatistics() { } public TyreStatistics(int imagesPerTyre, TyreJudgeRule judgeRule = TyreJudgeRule.AnyNG) { ImagesPerTyre = imagesPerTyre; JudgeRule = judgeRule; } #endregion #region æ ¸å¿æ¹æ³ /// <summary> /// æ·»å å¾åæ£æµç»æ /// </summary> /// <param name="isOK">å¾åæ£æµç»æ</param> /// <param name="imageSN">å¾ååºåå·ï¼å¯éï¼</param> /// <returns>è½®è计æ°ç»æ</returns> public TyreCountResult AddImageResult(bool isOK, string imageSN = null) { // æ·»å å°å½åè½®èç»æå表 CurrentTyreResults.Add(isOK); CurrentTyreImageSNs.Add(imageSN); CurrentImageIndex++; var result = new TyreCountResult { CurrentImageIndex = CurrentImageIndex, IsTyreComplete = false, Message = $"å½åè½®è第 {CurrentImageIndex}/{ImagesPerTyre} å¼ å¾å" }; // æ£æ¥æ¯å¦å®æä¸ä¸ªè½®è if (CurrentImageIndex >= ImagesPerTyre) { // 计ç®è½®èæ´ä½ç»æ bool tyreResult = CalculateTyreResult(); // æ´æ°ç»è®¡ if (tyreResult) TyreOK++; else TyreNG++; // æå»ºå®æç»æ result.IsTyreComplete = true; result.TyreID = CurrentTyreID; result.TyreResult = tyreResult; result.ImageResults = new List<bool>(CurrentTyreResults); result.Message = $"å®æè½®è #{CurrentTyreID}ï¼ç»æ: {(tyreResult ? "OK" : "NG")}"; // éç½®å½åè½®èæ°æ® ResetCurrentTyre(); } return result; } /// <summary> /// 计ç®è½®èæ´ä½ç»æ /// </summary> private bool CalculateTyreResult() { if (CurrentTyreResults.Count == 0) return true; switch (JudgeRule) { case TyreJudgeRule.AnyNG: // nå¼ ä¸ä»»ä¸NGåæ´èNG return !CurrentTyreResults.Any(r => !r); case TyreJudgeRule.AllOK: // å ¨é¨OKææ´èOKï¼ä¸AnyNGç¸åï¼ return CurrentTyreResults.All(r => r); case TyreJudgeRule.MajorityVote: // 夿°è¡¨å³ï¼è¶ è¿åæ°OKåOK int okCount = CurrentTyreResults.Count(r => r); return okCount > (CurrentTyreResults.Count / 2.0); default: return !CurrentTyreResults.Any(r => !r); } } /// <summary> /// éç½®å½åè½®èæ°æ® /// </summary> private void ResetCurrentTyre() { CurrentTyreID++; CurrentImageIndex = 0; CurrentTyreResults.Clear(); CurrentTyreImageSNs.Clear(); } /// <summary> /// éç½®ææç»è®¡ /// </summary> public void Reset() { TyreOK = 0; TyreNG = 0; CurrentTyreID = 1; ResetCurrentTyre(); } /// <summary> /// æ¸ ç©ºå½åè½®èï¼ç¨äºå¼å¸¸æ åµï¼ /// </summary> public void ClearCurrentTyre() { ResetCurrentTyre(); } /// <summary> /// è·åå½åè¿åº¦ä¿¡æ¯ /// </summary> public string GetProgressInfo() { if (ImagesPerTyre <= 1) return $"è½®è #{CurrentTyreID} (3D模å¼)"; return $"è½®è #{CurrentTyreID} - 第 {CurrentImageIndex}/{ImagesPerTyre} å¼ "; } /// <summary> /// è·åç»è®¡ä¿¡æ¯å符串 /// </summary> public string GetStatisticsInfo() { return $"è½®èæ»æ°: {TyreTotal}, OK: {TyreOK}, NG: {TyreNG}, è¯åç: {TyreRateOK:F2}%"; } #endregion } }