示例#1
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();

            imgBw8.SetSize(img);
            switch (Type)
            {
            case MorphologyType.Square:
                EasyImage.ErodeBox(img, imgBw8, Width);
                break;

            case MorphologyType.Rectangle:
                EasyImage.ErodeBox(img, imgBw8, Width, Height);
                break;

            case MorphologyType.Circle:
                EasyImage.ErodeDisk(img, imgBw8, Width);
                break;

            default: EasyImage.ErodeBox(img, imgBw8, Width);
                break;
            }
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
        private void FileListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selecting)
            {
                OriginalImg1.Load(files[0]);

                //============================計算scaling ratio============================
                float PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height;
                float ImageSizeRatio      = (float)OriginalImg1.Width / OriginalImg1.Height;
                if (ImageSizeRatio > PictureBoxSizeRatio)
                {
                    ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width;
                }
                else
                {
                    ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height;
                }
                //=========================================================================

                OriginalImg1.Load(files[FileListBox.SelectedIndex]);
                OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio);

                GrayImg1.SetSize(OriginalImg1);
                EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1);
                EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階

                EasyImage.Median(BackgroundGray, BackgroundGray);
                EasyImage.Median(GrayImg1, GrayImg1);
                EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1);

                EasyImage.Threshold(GrayImg1, GrayImg1, unchecked ((uint)EThresholdMode.MinResidue));

                EasyImage.ErodeBox(GrayImg1, GrayImg1, 1);  //侵蝕
                EasyImage.CloseBox(GrayImg1, GrayImg1, 10); //閉合

                GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio);

                Console.WriteLine(files[FileListBox.SelectedIndex]);
            }
        }
        private void vehicleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            float PictureBoxSizeRatio, ImageSizeRatio;

            codedImage1ObjectSelection.FeretAngle = 0.00f;
            codedImage1Encoder.GrayscaleSingleThresholdSegmenter.WhiteLayerEncoded = true;
            codedImage1Encoder.GrayscaleSingleThresholdSegmenter.BlackLayerEncoded = false;
            codedImage1Encoder.SegmentationMethod = ESegmentationMethod.GrayscaleSingleThreshold;
            codedImage1Encoder.GrayscaleSingleThresholdSegmenter.Mode = EGrayscaleSingleThreshold.MinResidue;

            OriginalImg1.Load(files[0]);

            /*============================計算scaling ratio============================*/
            PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height;
            ImageSizeRatio      = (float)OriginalImg1.Width / OriginalImg1.Height;
            if (ImageSizeRatio > PictureBoxSizeRatio)
            {
                ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width;
            }
            else
            {
                ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height;
            }
            /*=========================================================================*/

            for (int i = 0; i < FileListBox.Items.Count; i++)
            {
                FileListBox.SelectedIndex = i;
                FileListBox.Refresh();
                OriginalImg1.Load(files[i]);
                OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio);

                GrayImg1.SetSize(OriginalImg1);
                EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1);
                EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階

                EasyImage.Median(BackgroundGray, BackgroundGray);
                EasyImage.Median(GrayImg1, GrayImg1);
                EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1);

                EasyImage.Threshold(GrayImg1, GrayImg1, unchecked ((uint)EThresholdMode.MinResidue));

                EasyImage.ErodeBox(GrayImg1, GrayImg1, 1);  //侵蝕
                EasyImage.CloseBox(GrayImg1, GrayImg1, 10); //閉合

                codedImage1ObjectSelection.FeretAngle = 0.00f;
                codedImage1Encoder.Encode(GrayImg1, codedImage1);
                codedImage1ObjectSelection.Clear();
                codedImage1ObjectSelection.AddObjects(codedImage1);
                codedImage1ObjectSelection.AttachedImage = GrayImg1;
                codedImage1ObjectSelection.RemoveUsingUnsignedIntegerFeature(EFeature.RunCount, 1000, ESingleThresholdMode.Less); //移除RunCount小於1000的物件

                if (codedImage1ObjectSelection.ElementCount > 0)
                {
                    Console.WriteLine("(" + codedImage1ObjectSelection.GetElement(0).BoundingBoxCenterX + ", " + codedImage1ObjectSelection.GetElement(0).BoundingBoxCenterY + ")");
                }

                codedImage1.DrawFeature(pbImg1.CreateGraphics(), EDrawableFeature.BoundingBox, codedImage1ObjectSelection, ScalingRatio); // 把車的框框畫出來

                GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio);

                Console.WriteLine(files[i]);
            }
        }