public void configNew() { //ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); //ManagementObjectCollection nics = mc.GetInstances(); //foreach (ManagementObject nic in nics) //{ // if (Convert.ToBoolean(nic["ipEnabled"]) == true) // { //string mac = nic["MacAddress"].ToString();//Mac地址 //ip = (nic["IPAddress"] as String[])[0];//IP地址 //ipsubnet = (nic["IPSubnet"] as String[])[0];//子网掩码 //ipgateway = (nic["DefaultIPGateway"] as String[])[0];//默认网关 // } //} this.txtbox_IP.Text = ""; this.txtbox_mask.Text = ""; this.txtbox_gate.Text = ""; listDevice = Common.ToDataList <device>(DBSet.ReadCSV(@"..\device.csv")); dataGridView_device.DataSource = DBSet.ReadCSV(@"..\device.csv"); listUser = Common.ToDataList <user>(DBSet.ReadCSV(@"..\user.csv")); dataGridViewUser.DataSource = DBSet.ReadCSV(@"..\user.csv"); listTool = Common.ToDataList <tool>(DBSet.ReadCSV(@"..\tool.csv")); dataGridViewTool.DataSource = DBSet.ReadCSV(@"..\tool.csv"); }
private void btn_search_device_Click(object sender, EventArgs e) { try { this.dataGridView_device.DataSource = DBSet.ReadCSV(@"..\device.csv"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnToolSearch_Click(object sender, EventArgs e) { this.dataGridViewTool.DataSource = DBSet.ReadCSV(@"..\tool.csv"); }
private void btnUserSearch_Click(object sender, EventArgs e) { this.dataGridViewUser.DataSource = DBSet.ReadCSV(@"..\user.csv"); }
private void FZ2() { tools_second.Clear(); bmp_secend = videoSourcePlayer1.GetCurrentVideoFrame(); pictureBox1.Image = bmp_secend; this.videoSourcePlayer1.Visible = true; this.pictureBox1.Visible = false; DirectoryInfo root = new DirectoryInfo("tools//"); DirectoryInfo[] dics = root.GetDirectories(); progressBar.Value = 0; progressBar.Maximum = dics.Length; Bitmap x = ConvertToFormat(bmp_secend, PixelFormat.Format24bppRgb); try { txtbox_msg.Text = "图像处理中"; foreach (var path in dics) { Bitmap sourceImage = ConvertToFormat(System.Drawing.Image.FromFile(path.GetFiles()[0].FullName), PixelFormat.Format24bppRgb); // 创建模板匹配算法的实例 //(将相似度阈值设置为92.5%) string temp = path.Name; DataTable dataTable1 = DBSet.ReadCSV(@"..\tool.csv"); List <tool> listTool1 = Common.ToDataList <tool>(dataTable1); foreach (tool a in listTool1) { if (a.picture == temp) { Rectangle p = new Rectangle(Convert.ToInt32(a.x) - 10, Convert.ToInt32(a.y) - 10, Convert.ToInt32(a.w) + 20, Convert.ToInt32(a.h) + 20); Bitmap targetImage = (Bitmap)AcquireRectangleImage1(x, p); Bitmap cp = targetImage.Clone() as Bitmap; // 复制原始图像 FiltersSequence seq = new FiltersSequence(); seq.Add(Grayscale.CommonAlgorithms.BT709); // 添加灰度滤镜 seq.Add(new OtsuThreshold()); // 添加二值化滤镜 cp = seq.Apply(targetImage); // 应用滤镜 cp = ConvertToFormat(cp, PixelFormat.Format24bppRgb); ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.85f); //查找具有上述指定相似性的所有匹配项 TemplateMatch[] matchings = tm.ProcessImage(cp, sourceImage); if (matchings.Length != 0) { tools_second.Add(path.Name); //高亮发现的匹配 using (Graphics g = Graphics.FromImage(targetImage)) { if (matchings.Length != 0) { foreach (TemplateMatch m in matchings) { g.DrawRectangle(new Pen(Color.Red, 1), m.Rectangle); } } } //using (Graphics g = Graphics.FromImage(x)) //{ // g.DrawRectangle(new Pen(Color.Red, 1), p); //} //Random rd = new Random(); //targetImage.Save("result\\" + path.Name + rd.Next(0, 100) + "2.jpg"); //break; } } } sourceImage.Dispose(); progressBar.Value++; dataTable1.Dispose(); } List <string> pick = new List <string>(); List <string> putIn = new List <string>(); if (tools_first.Count >= tools_second.Count) { pick = (tools_first.Distinct()).Except(tools_second.Distinct()).ToList(); } if (tools_first.Count <= tools_second.Count) { putIn = (tools_second.Distinct()).Except(tools_first.Distinct()).ToList(); } progressBar.Value = 0; DataTable dataTable = DBSet.ReadCSV(@"..\tool.csv"); List <tool> listTool = Common.ToDataList <tool>(dataTable); if (pick.Count != 0 || putIn.Count != 0) { dataGridView1.Rows.Clear(); foreach (var i in pick) { foreach (tool a in listTool) { if (a.picture == i) { int index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = "领取"; dataGridView1.Rows[index].Cells[1].Value = a.No; dataGridView1.Rows[index].Cells[2].Value = a.name; dataGridView1.Rows[index].Cells[3].Value = a.address; dataGridView1.Rows[index].Cells[4].Value = ConvertToFormat(System.Drawing.Image.FromFile("tools//" + i + "//" + i + "_2.jpg"), PixelFormat.Format24bppRgb); dataGridView1.Rows[index].Cells[5].Value = DateTime.Now.ToString("HH:mm:ss"); } } } foreach (var j in putIn) { foreach (tool a in listTool) { if (a.picture == j) { int index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = "归还"; dataGridView1.Rows[index].Cells[1].Value = a.No; dataGridView1.Rows[index].Cells[2].Value = a.name; dataGridView1.Rows[index].Cells[3].Value = a.address; dataGridView1.Rows[index].Cells[4].Value = ConvertToFormat(System.Drawing.Image.FromFile("tools//" + j + "//" + j + "_2.jpg"), PixelFormat.Format24bppRgb); dataGridView1.Rows[index].Cells[5].Value = DateTime.Now.ToString("HH:mm:ss"); } } } } dataTable.Dispose(); txtbox_msg.Text = "处理完成!!!"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void FZ() { Thread.Sleep(500); tools_first.Clear(); bmp_first = videoSourcePlayer1.GetCurrentVideoFrame(); //pictureBox1.Image = bmp_first; //bmp_first.Save("result\\2.jpg"); this.videoSourcePlayer1.Visible = false; this.pictureBox1.Visible = true; DirectoryInfo root = new DirectoryInfo("tools//"); DirectoryInfo[] dics = root.GetDirectories(); Bitmap x = ConvertToFormat(bmp_first, PixelFormat.Format24bppRgb); progressBar.Value = 0; progressBar.Maximum = dics.Length; try { txtbox_msg.Text = "图像处理中"; foreach (var path in dics) { Bitmap sourceImage = ConvertToFormat(System.Drawing.Image.FromFile(path.GetFiles()[0].FullName), PixelFormat.Format24bppRgb); // 创建模板匹配算法的实例 //(将相似度阈值设置为92.5%) string temp = path.Name; DataTable dataTable = DBSet.ReadCSV(@"..\tool.csv"); List <tool> listTool = Common.ToDataList <tool>(dataTable); foreach (tool a in listTool) { if (a.picture == temp) { Rectangle p = new Rectangle(Convert.ToInt32(a.x) - 10, Convert.ToInt32(a.y) - 10, Convert.ToInt32(a.w) + 20, Convert.ToInt32(a.h) + 20); Bitmap targetImage = (Bitmap)AcquireRectangleImage1(x, p); Bitmap cp = targetImage.Clone() as Bitmap; // 复制原始图像 FiltersSequence seq = new FiltersSequence(); seq.Add(Grayscale.CommonAlgorithms.BT709); // 添加灰度滤镜 seq.Add(new OtsuThreshold()); // 添加二值化滤镜 cp = seq.Apply(targetImage); // 应用滤镜 cp = ConvertToFormat(cp, PixelFormat.Format24bppRgb); ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.85f); //查找具有上述指定相似性的所有匹配项 TemplateMatch[] matchings = tm.ProcessImage(cp, sourceImage); if (matchings.Length != 0) { tools_first.Add(path.Name); //高亮发现的匹配 using (Graphics g = Graphics.FromImage(targetImage)) { if (matchings.Length != 0) { foreach (TemplateMatch m in matchings) { g.DrawRectangle(new Pen(Color.Red, 1), m.Rectangle); } } } //using (Graphics g = Graphics.FromImage(x)) //{ // g.DrawRectangle(new Pen(Color.Red, 1), p); //} Random rd = new Random(); targetImage.Save("result\\" + path.Name + rd.Next(0, 100) + "1.jpg"); break; } } } sourceImage.Dispose(); progressBar.Value++; } txtbox_msg.Text = "处理完成!!!"; this.pictureBox1.Visible = false; pictureBox1.Image = x; progressBar.Value = 0; } catch (Exception ex) { MessageBox.Show(ex.Message); } }