コード例 #1
0
        private bool GetBlob(EImageBW8 inputImage, ref DataTable blobTable)
        {
            bool reSuccess = false;

            try
            {
                eObjectSelection.Clear();
                eObjectSelection.AddObjects(Base);
                eObjectSelection.AttachedImage = inputImage;

                blobTable.Clear();

                ECodedElement blob;
                for (int i = 0; i < eObjectSelection.ElementCount; i++)
                {
                    blob = eObjectSelection.GetElement(i);
                    int   area    = blob.Area;
                    float centerX = blob.GravityCenterX;
                    float centerY = blob.GravityCenterY;

                    blobTable.Rows.Add(i + 1, area, centerX, centerY);
                }

                reSuccess = true;
            }
            catch (EException exc)
            {
                StackFrame[] stackFrames = new StackTrace(true).GetFrames();
                clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true);
            }
            catch (Exception ex)
            {
                StackFrame[] stackFrames = new StackTrace(true).GetFrames();
                clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true);
            }
            return(reSuccess);
        }
コード例 #2
0
        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]);
            }
        }