diff --git a/Windows/CS/Framework4.0/Camera/Camera/Camera.cs b/Windows/CS/Framework4.0/Camera/Camera/Camera.cs index 2576f29..3be679c 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Camera.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/Camera.cs @@ -23,7 +23,7 @@ namespace Camera private const string PASSWD = "Yexian.net.168"; // 调试模式 - private const Boolean IsDebug = true; + private const Boolean IsDebug = false; // 配置文件目录 private string _configPath; @@ -33,6 +33,7 @@ namespace Camera private ConcurrentDictionary _ledZones = new ConcurrentDictionary(); private ConcurrentDictionary _ledZoneColors = new ConcurrentDictionary(); private ConcurrentDictionary _ledZoneDetectionResults = new ConcurrentDictionary(); + private ConcurrentDictionary> _ledZoneHsvValues = new ConcurrentDictionary>(); private LedDetector _ledDetector = new LedDetector(); public void SetLedDetectorParams(int brightLimit, int satLimit) @@ -434,6 +435,24 @@ namespace Camera _ledZoneDetectionResults[index] = result; } + /// + /// 获取所有LED区域的HSV值 + /// + public ConcurrentDictionary> GetLedZoneHsvValues() + { + return _ledZoneHsvValues; + } + + /// + /// 获取指定索引的LED区域的HSV值 + /// + public Tuple GetLedZoneHsvValue(int index) + { + if (_ledZoneHsvValues.ContainsKey(index)) + return _ledZoneHsvValues[index]; + return new Tuple(0, 0, 0); + } + /// /// 保存配置 /// @@ -495,7 +514,6 @@ namespace Camera { string line; bool isDetectionZone = true; - bool isReadingLedThresholds = false; while ((line = reader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) @@ -677,6 +695,7 @@ namespace Camera result = "Off"; } _ledZoneDetectionResults[index] = result; + _ledZoneHsvValues[index] = new Tuple(detectResult.Item3, detectResult.Item4, detectResult.Item5); } } } diff --git a/Windows/CS/Framework4.0/Camera/Camera/LedDetector.cs b/Windows/CS/Framework4.0/Camera/Camera/LedDetector.cs index 06e19eb..10e863b 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/LedDetector.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/LedDetector.cs @@ -24,7 +24,7 @@ public class LedDetector set { _satLimit = value; } } - public Tuple Detect(Image image, Rectangle roi) + public Tuple Detect(Image image, Rectangle roi) { using (Image subImg = image.GetSubRect(roi)) using (Image hsv = subImg.Convert()) @@ -41,12 +41,11 @@ public class LedDetector S.Dispose(); V.Dispose(); - //bool isOn = avgV > _brightLimit; bool isOn = avgV > _brightLimit && avgS > _satLimit; if (!isOn) { - return new Tuple(LedState.Off, LedColor.Unknown); + return new Tuple(LedState.Off, LedColor.Unknown, avgH, avgS, avgV); } LedColor color = LedColor.Unknown; @@ -57,7 +56,7 @@ public class LedDetector else if (avgH >= 90 && avgH < 130) color = LedColor.Blue; - return new Tuple(LedState.On, color); + return new Tuple(LedState.On, color, avgH, avgS, avgV); } } } diff --git a/Windows/CS/Framework4.0/Camera/Camera/Setting.Designer.cs b/Windows/CS/Framework4.0/Camera/Camera/Setting.Designer.cs index f2dccd1..737afdb 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Setting.Designer.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/Setting.Designer.cs @@ -40,7 +40,9 @@ namespace Camera this.toolStripNumericUpDown3 = new ToolStripNumericUpDown(); this.toolStripLabel4 = new System.Windows.Forms.ToolStripLabel(); this.toolStripNumericUpDown4 = new ToolStripNumericUpDown(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dataGridView2 = new System.Windows.Forms.DataGridView(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -50,7 +52,12 @@ namespace Camera this.toolStrip2.SuspendLayout(); this.toolStrip3.SuspendLayout(); this.toolStripContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); this.SuspendLayout(); // // splitContainer1 @@ -58,6 +65,7 @@ namespace Camera this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.SplitterWidth = 5; // // splitContainer1.Panel1 // @@ -92,7 +100,6 @@ namespace Camera this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.toolStripContainer1.Location = new System.Drawing.Point(0, 0); this.toolStripContainer1.Name = "toolStripContainer1"; - this.toolStripContainer1.Size = new System.Drawing.Size(559, 515); this.toolStripContainer1.TabIndex = 0; this.toolStripContainer1.Text = "toolStripContainer1"; this.toolStripContainer1.TopToolStripPanel.Dock = System.Windows.Forms.DockStyle.Top; @@ -103,7 +110,7 @@ namespace Camera // // toolStripContainer1.ContentPanel // - this.toolStripContainer1.ContentPanel.Controls.Add(this.dataGridView1); + this.toolStripContainer1.ContentPanel.Controls.Add(this.splitContainer2); this.toolStripContainer1.ContentPanel.Dock = System.Windows.Forms.DockStyle.Fill; // // toolStrip1 @@ -420,6 +427,7 @@ namespace Camera this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.ColumnHeadersHeight = 25; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + // this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this.dataGridView1.Location = new System.Drawing.Point(0, 0); @@ -427,10 +435,46 @@ namespace Camera this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 25; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView1.Size = new System.Drawing.Size(559, 254); + this.dataGridView1.Size = new System.Drawing.Size(600, 254); this.dataGridView1.TabIndex = 0; this.dataGridView1.SelectionChanged += new System.EventHandler(this.DataGridView1_SelectionChanged); // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Name = "splitContainer2"; + this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; + this.splitContainer2.SplitterWidth = 5; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.dataGridView1); + this.splitContainer2.Panel1MinSize = 50; + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.dataGridView2); + this.splitContainer2.Panel2MinSize = 50; + this.splitContainer2.TabIndex = 1; + // + // dataGridView2 + // + this.dataGridView2.AllowUserToAddRows = false; + this.dataGridView2.AllowUserToDeleteRows = false; + this.dataGridView2.AllowUserToResizeRows = false; + this.dataGridView2.Enabled = false; + this.dataGridView2.ColumnHeadersHeight = 25; + this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView2.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.dataGridView2.Name = "dataGridView2"; + this.dataGridView2.ReadOnly = true; + this.dataGridView2.RowHeadersVisible = false; + this.dataGridView2.RowTemplate.Height = 25; + this.dataGridView2.Size = new System.Drawing.Size(600, 254); + this.dataGridView2.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView2.TabIndex = 0; + // // Setting // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); @@ -455,7 +499,9 @@ namespace Camera this.toolStrip3.PerformLayout(); this.toolStripContainer1.ResumeLayout(false); this.toolStripContainer1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.ResumeLayout(false); } @@ -486,5 +532,7 @@ namespace Camera private System.Windows.Forms.ToolStripLabel toolStripLabel6; private ToolStripNumericUpDown toolStripNumericUpDown6; private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.DataGridView dataGridView2; } } \ No newline at end of file diff --git a/Windows/CS/Framework4.0/Camera/Camera/Setting.cs b/Windows/CS/Framework4.0/Camera/Camera/Setting.cs index 1f7bc55..f8d3735 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Setting.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/Setting.cs @@ -197,6 +197,19 @@ namespace Camera dataGridView1.Columns["Color"].Width = 70; dataGridView1.Columns["Detection"].Width = 80; } + + if (dataGridView2.Columns.Count == 0) + { + dataGridView2.Columns.Add("Index", "索引"); + dataGridView2.Columns.Add("H", "H值"); + dataGridView2.Columns.Add("S", "S值"); + dataGridView2.Columns.Add("V", "V值"); + + dataGridView2.Columns["Index"].Width = 50; + dataGridView2.Columns["H"].Width = 80; + dataGridView2.Columns["S"].Width = 80; + dataGridView2.Columns["V"].Width = 80; + } } private void Setting_Load(object sender, EventArgs e) @@ -214,6 +227,11 @@ namespace Camera picBoxCamera.BackColor = Color.Gray; splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; splitContainer1.SplitterDistance = splitContainer1.Width - splitContainer1.Panel2MinSize; + this.BeginInvoke(new Action(() => + { + if (splitContainer2.Height > 0) + splitContainer2.SplitterDistance = splitContainer2.Height / 2; + })); UpdateDataGridView(); UpdateLedZoneButtonsVisibility(0); } @@ -354,6 +372,7 @@ namespace Camera { Rectangle detectionZone = _camera.GetDetectionZone(); var allLedZones = _camera.GetLedZones(); + var hsvValues = _camera.GetLedZoneHsvValues(); foreach (var kvp in allLedZones) { int index = kvp.Key; @@ -366,6 +385,21 @@ namespace Camera dataGridView1.Rows.Add(index, ledZone.X, ledZone.Y, ledZone.Width, ledZone.Height, ColorTranslator.ToHtml(ledColor), detectionResult); } } + + dataGridView2.Rows.Clear(); + foreach (var kvp in allLedZones) + { + int index = kvp.Key; + if (hsvValues.ContainsKey(index)) + { + var hsv = hsvValues[index]; + dataGridView2.Rows.Add(index, hsv.Item1.ToString("F1"), hsv.Item2.ToString("F1"), hsv.Item3.ToString("F1")); + } + else + { + dataGridView2.Rows.Add(index, "0", "0", "0"); + } + } } picBoxCamera.Invalidate(); _isUpdatingDataGridView = false; @@ -396,6 +430,8 @@ namespace Camera } } + UpdateHsvResults(); + if (selectedIndex >= 0) { foreach (DataGridViewRow row in dataGridView1.Rows) @@ -414,6 +450,59 @@ namespace Camera } } + private void UpdateHsvResults() + { + if (_camera == null || dataGridView2.Rows.Count == 0) return; + + var allLedZones = _camera.GetLedZones(); + var hsvValues = _camera.GetLedZoneHsvValues(); + + if (dataGridView2.Rows.Count != allLedZones.Count) + { + dataGridView2.Rows.Clear(); + foreach (var kvp in allLedZones) + { + int index = kvp.Key; + if (hsvValues.ContainsKey(index)) + { + var hsv = hsvValues[index]; + dataGridView2.Rows.Add(index, hsv.Item1.ToString("F1"), hsv.Item2.ToString("F1"), hsv.Item3.ToString("F1")); + } + else + { + dataGridView2.Rows.Add(index, "0", "0", "0"); + } + } + } + else + { + foreach (DataGridViewRow row in dataGridView2.Rows) + { + int index = Convert.ToInt32(row.Cells["Index"].Value); + if (hsvValues.ContainsKey(index)) + { + var hsv = hsvValues[index]; + row.Cells["H"].Value = hsv.Item1.ToString("F1"); + row.Cells["S"].Value = hsv.Item2.ToString("F1"); + row.Cells["V"].Value = hsv.Item3.ToString("F1"); + } + } + } + + if (dataGridView1.SelectedRows.Count > 0) + { + int selectedIndex = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Index"].Value); + foreach (DataGridViewRow row in dataGridView2.Rows) + { + if (Convert.ToInt32(row.Cells["Index"].Value) == selectedIndex) + { + row.Selected = true; + break; + } + } + } + } + private void PicBoxCamera_Paint(object sender, PaintEventArgs e) { Image currentImage = null; @@ -1199,6 +1288,14 @@ namespace Camera toolStripNumericUpDown3.Value = zone.Width; toolStripNumericUpDown4.Value = zone.Height; } + foreach (DataGridViewRow row in dataGridView2.Rows) + { + if (Convert.ToInt32(row.Cells["Index"].Value) == newSelectedZoneIndex) + { + row.Selected = true; + break; + } + } picBoxCamera.Invalidate(); } }