예제 #1
0
        private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            object o = e.Item.Tag;

            if (o is DilateConfig)
            {
                DilateConfig config = o as DilateConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is ErodeConfig)
            {
                ErodeConfig config = o as ErodeConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is OpenConfig)
            {
                OpenConfig config = o as OpenConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is CloseConfig)
            {
                CloseConfig config = o as CloseConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is ThresholdConfig)
            {
                ThresholdConfig config = o as ThresholdConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is GainOffsetConfig)
            {
                GainOffsetConfig config = o as GainOffsetConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is RoataeConfig)
            {
                RoataeConfig config = o as RoataeConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is MedianConfig)
            {
                MedianConfig config = o as MedianConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is SobelConfig)
            {
                SobelConfig config = o as SobelConfig;
                config.Enable = e.Item.Checked;
            }
            //Run();
        }
예제 #2
0
 private void rdbtn_Relative_CheckedChanged(object sender, EventArgs e)
 {
     if (rdbtn_Relative.Checked)
     {
         valueControl1.Enabled = true;
         valueControl1.Max     = 99;
         ThresholdConfig config = tabPage_Threshold.Tag as ThresholdConfig;
         if (config != null)
         {
             config.Mode = ThresholdConfig.MyThresholdMode.Relative;
             Run();
             valueControl1.Value = (int)(config.RelativeValue * 100);
             foreach (ListViewItem item in listView1.Items)
             {
                 if (item.Tag == config)
                 {
                     item.SubItems[2].Text = config.RelativeValue.ToString();
                 }
             }
         }
     }
 }
예제 #3
0
        private void rdbtn_Auto_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbtn_Auto.Checked)
            {
                valueControl1.Enabled = false;
                valueControl1.Max     = 255;
                ThresholdConfig config = tabPage_Threshold.Tag as ThresholdConfig;
                if (config != null)
                {
                    config.Mode = ThresholdConfig.MyThresholdMode.Auto;
                    Run();
                    valueControl1.Value = config.AbsoluteValue;

                    foreach (ListViewItem item in listView1.Items)
                    {
                        if (item.Tag == config)
                        {
                            item.SubItems[2].Text = "Auto";
                        }
                    }
                }
            }
        }
예제 #4
0
        private void valueControl1_ValueChanged(object o, ValueControl.ValueChangedEventArgs e)
        {
            if (this.m_lock.WaitOne(0))
            {
                ThresholdConfig config = tabPage_Threshold.Tag as ThresholdConfig;
                if (config != null)
                {
                    if (config.Mode == ThresholdConfig.MyThresholdMode.Absolute)
                    {
                        config.AbsoluteValue = e.Value;
                    }
                    else if (config.Mode == ThresholdConfig.MyThresholdMode.Relative)
                    {
                        config.RelativeValue = (float)e.Value / 100f;
                    }

                    foreach (ListViewItem item in listView1.Items)
                    {
                        if (item.Tag == config)
                        {
                            if (config.Mode == ThresholdConfig.MyThresholdMode.Absolute)
                            {
                                item.SubItems[2].Text = config.AbsoluteValue.ToString();
                            }
                            else if (config.Mode == ThresholdConfig.MyThresholdMode.Relative)
                            {
                                item.SubItems[2].Text = config.RelativeValue.ToString();
                            }
                        }
                    }
                    Run();
                }

                this.m_lock.Release();
            }
        }
예제 #5
0
        protected override void UpdateEventToUI()
        {
            base.UpdateEventToUI();

            foreach (var o in imgEvent.config.CfgGroup)
            {
                ListViewItem item = new ListViewItem();
                if (o is DilateConfig)
                {
                    DilateConfig config = o as DilateConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is ErodeConfig)
                {
                    ErodeConfig config = o as ErodeConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is OpenConfig)
                {
                    OpenConfig config = o as OpenConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is CloseConfig)
                {
                    CloseConfig config = o as CloseConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is ThresholdConfig)
                {
                    ThresholdConfig config = o as ThresholdConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    switch (config.Mode)
                    {
                    case ThresholdConfig.MyThresholdMode.Auto:
                        item.SubItems.Add("Auto");
                        break;

                    case ThresholdConfig.MyThresholdMode.Absolute:
                        item.SubItems.Add(config.AbsoluteValue.ToString());
                        break;

                    case ThresholdConfig.MyThresholdMode.Relative:
                        item.SubItems.Add(config.RelativeValue.ToString());
                        break;

                    default:
                        break;
                    }

                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is GainOffsetConfig)
                {
                    GainOffsetConfig config = o as GainOffsetConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Gain.ToString() + "," + config.Offset.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is RoataeConfig)
                {
                    RoataeConfig config = o as RoataeConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Value.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is MedianConfig)
                {
                    MedianConfig config = o as MedianConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is SobelConfig)
                {
                    SobelConfig config = o as SobelConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                listView1.Items.Add(item);
            }
        }
예제 #6
0
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (listView1.SelectedItems.Count <= 0)
            {
                return;
            }
            object o = listView1.SelectedItems[0].Tag;

            if (o is DilateConfig)
            {
                tabControl1.SelectedTab = tabPage_Morphology;
                tabPage_Morphology.Tag  = o;
                DilateConfig config = o as DilateConfig;
                vlctrl_width.Value  = config.Width;
                vlctrl_height.Value = config.Height;
                switch (config.Type)
                {
                case MorphologyType.Square: rdbtn_square.Checked = true;
                    break;

                case MorphologyType.Rectangle: rdbtn_rect.Checked = true;
                    break;

                case MorphologyType.Circle: rdbtn_circle.Checked = true;
                    break;

                default:
                    break;
                }
            }
            else if (o is ErodeConfig)
            {
                tabControl1.SelectedTab = tabPage_Morphology;
                tabPage_Morphology.Tag  = o;
                ErodeConfig config = o as ErodeConfig;
                vlctrl_width.Value  = config.Width;
                vlctrl_height.Value = config.Height;
                switch (config.Type)
                {
                case MorphologyType.Square: rdbtn_square.Checked = true;
                    break;

                case MorphologyType.Rectangle: rdbtn_rect.Checked = true;
                    break;

                case MorphologyType.Circle: rdbtn_circle.Checked = true;
                    break;

                default:
                    break;
                }
            }
            else if (o is OpenConfig)
            {
                tabControl1.SelectedTab = tabPage_Morphology;
                tabPage_Morphology.Tag  = o;
                OpenConfig config = o as OpenConfig;
                vlctrl_width.Value  = config.Width;
                vlctrl_height.Value = config.Height;
                switch (config.Type)
                {
                case MorphologyType.Square: rdbtn_square.Checked = true;
                    break;

                case MorphologyType.Rectangle: rdbtn_rect.Checked = true;
                    break;

                case MorphologyType.Circle: rdbtn_circle.Checked = true;
                    break;

                default:
                    break;
                }
            }
            else if (o is CloseConfig)
            {
                tabControl1.SelectedTab = tabPage_Morphology;
                tabPage_Morphology.Tag  = o;
                CloseConfig config = o as CloseConfig;
                vlctrl_width.Value  = config.Width;
                vlctrl_height.Value = config.Height;
                switch (config.Type)
                {
                case MorphologyType.Square: rdbtn_square.Checked = true;
                    break;

                case MorphologyType.Rectangle: rdbtn_rect.Checked = true;
                    break;

                case MorphologyType.Circle: rdbtn_circle.Checked = true;
                    break;

                default:
                    break;
                }
            }
            else if (o is ThresholdConfig)
            {
                tabControl1.SelectedTab = tabPage_Threshold;
                tabPage_Threshold.Tag   = o;
                ThresholdConfig config = o as ThresholdConfig;
                switch (config.Mode)
                {
                case ThresholdConfig.MyThresholdMode.Auto:
                    rdbtn_Auto.Checked  = true;
                    valueControl1.Value = config.AbsoluteValue;
                    break;

                case ThresholdConfig.MyThresholdMode.Absolute:
                    rdbtn_Absolute.Checked = true;
                    valueControl1.Value    = config.AbsoluteValue;
                    break;

                case ThresholdConfig.MyThresholdMode.Relative:
                    rdbtn_Relative.Checked = true;
                    valueControl1.Value    = (int)(config.RelativeValue * 100);
                    break;

                default:
                    break;
                }
            }
            else if (o is GainOffsetConfig)
            {
                tabControl1.SelectedTab = tabPage_GainOffset;
                tabPage_GainOffset.Tag  = o;
                GainOffsetConfig config = o as GainOffsetConfig;
                floatValueControl1.Value = config.Gain;
                valueControl4.Value      = (int)config.Offset;
            }
            else if (o is RoataeConfig)
            {
                tabControl1.SelectedTab = tabPage_Roatae;
                tabPage_Roatae.Tag      = o;
                RoataeConfig config = o as RoataeConfig;
                valueControl3.Value = config.Value;
            }
            else if (o is MedianConfig || o is SobelConfig)
            {
                tabControl1.SelectedIndex = 0;
            }
        }
예제 #7
0
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripItem tsi  = sender as ToolStripItem;
            ListViewItem  item = new ListViewItem();

            switch (tsi.Text)
            {
            case "膨胀":
                DilateConfig dc = new DilateConfig();
                imgEvent.config.CfgGroup.Add(dc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(dc.Name);
                item.SubItems.Add(dc.Width.ToString() + "," + dc.Height.ToString());
                item.Tag = dc;
                break;

            case "腐蚀":
                ErodeConfig ec = new ErodeConfig();
                imgEvent.config.CfgGroup.Add(ec);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(ec.Name);
                item.SubItems.Add(ec.Width.ToString() + "," + ec.Height.ToString());
                item.Tag = ec;
                break;

            case "开运算":
                OpenConfig oc = new OpenConfig();
                imgEvent.config.CfgGroup.Add(oc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(oc.Name);
                item.SubItems.Add(oc.Width.ToString() + "," + oc.Height.ToString());
                item.Tag = oc;
                break;

            case "闭运算":
                CloseConfig cc = new CloseConfig();
                imgEvent.config.CfgGroup.Add(cc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(cc.Name);
                item.SubItems.Add(cc.Width.ToString() + "," + cc.Height.ToString());
                item.Tag = cc;
                break;

            case "二值化":
                ThresholdConfig tc = new ThresholdConfig();
                imgEvent.config.CfgGroup.Add(tc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(tc.Name);
                switch (tc.Mode)
                {
                case ThresholdConfig.MyThresholdMode.Auto:
                    item.SubItems.Add("Auto");
                    break;

                case ThresholdConfig.MyThresholdMode.Absolute:
                    item.SubItems.Add(tc.AbsoluteValue.ToString());
                    break;

                case ThresholdConfig.MyThresholdMode.Relative:
                    item.SubItems.Add(tc.RelativeValue.ToString());
                    break;

                default:
                    break;
                }

                item.Tag = tc;
                break;

            case "亮度调节":
                GainOffsetConfig gc = new GainOffsetConfig();
                imgEvent.config.CfgGroup.Add(gc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(gc.Name);
                item.SubItems.Add(gc.Gain.ToString() + "," + gc.Offset.ToString());
                item.Tag = gc;
                break;

            case "旋转":
                RoataeConfig rc = new RoataeConfig();
                imgEvent.config.CfgGroup.Add(rc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(rc.Name);
                item.SubItems.Add(rc.Value.ToString());
                item.Tag = rc;
                break;

            case "中值运算":
                MedianConfig mc = new MedianConfig();
                imgEvent.config.CfgGroup.Add(mc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(mc.Name);
                item.Tag = mc;
                break;

            case "Sobel运算":
                SobelConfig sc = new SobelConfig();
                imgEvent.config.CfgGroup.Add(sc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(sc.Name);
                item.Tag = sc;
                break;

            default:
                break;
            }
            item.Checked = true;

            listView1.Items.Add(item);
            Run();
        }