コード例 #1
0
        public Button RecognizeOneButton(Bitmap source, Rectangle rect, string filePath, int id)
        {
            var seq  = new FiltersSequence();
            var card = new Button(source); //Create Card Object

            card.Rect = rect;

            seq.Clear();

            seq.Add(Grayscale.CommonAlgorithms.BT709);
            seq.Add(new OtsuThreshold());
            source = seq.Apply(source);

            card.Tip = ScanButtonTip(source); //Scan Rank of non-face card

            //if (card.Tip == ButtonTip.NOT_RECOGNIZED)
            //{
            //    if (!string.IsNullOrEmpty(filePath))
            //    {
            //        while (File.Exists(filePath + id + ".bmp"))
            //            id++;
            //        top.Save(filePath + id + ".bmp", ImageFormat.Bmp);
            //    }
            //}

            return(card);
        }
コード例 #2
0
        public CardRecognizer()
        {
            //Initialize common filter sequence , this sequence generally will be applied
            commonSeq = new FiltersSequence();
            commonSeq.Add(Grayscale.CommonAlgorithms.BT709);
            commonSeq.Add(new OtsuThreshold());
            commonSeq.Add(new DifferenceEdgeDetector());

            Stream          strm;
            BinaryFormatter bformat;

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            strm    = File.Open("NetworkLetra.net", FileMode.Open);
            bformat = new BinaryFormatter();

            NetworkLetra = (FeedforwardNetwork)bformat.Deserialize(strm);

            strm    = File.Open("NetworkSuits.net", FileMode.Open);
            bformat = new BinaryFormatter();

            NetworkSuits = (FeedforwardNetwork)bformat.Deserialize(strm);

            strm    = File.Open("NetworkNumero.net", FileMode.Open);
            bformat = new BinaryFormatter();

            NetworkNumero = (FeedforwardNetwork)bformat.Deserialize(strm);

            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
        }
コード例 #3
0
        public VideoProcessor()
        {
            background = null;

            pixelateFilter           = new Pixellate();
            pixelateFilter.PixelSize = 10;

            differenceFilter = new Difference();
            thresholdFilter  = new Threshold(15);
            grayscaleFilter  = new Grayscale(0.2125, 0.7154, 0.0721);
            erosionFilter    = new Erosion();

            moveTowardsFilter = new MoveTowards();

            filters1 = new FiltersSequence();
            filters1.Add(pixelateFilter);
            filters1.Add(grayscaleFilter);

            filters2 = new FiltersSequence();

            filters2.Add(differenceFilter);
            filters2.Add(thresholdFilter);
            filters2.Add(erosionFilter);

            rat1 = new Tracker(640 / 2, 480 / 2, Color.Red);

            rat2 = new Tracker(400, 300, Color.Green);

            counter = 0;
        }
コード例 #4
0
 // Constructor
 public MotionDetector2()
 {
     processingFilter.Add(differenceFilter);
     processingFilter.Add(thresholdFilter);
     processingFilter.Add(openingFilter);
     processingFilter.Add(edgesFilter);
 }
コード例 #5
0
        private void button8_Click(object sender, EventArgs e)
        {
            FiltersSequence filter = new FiltersSequence();

            byte[,] matrix = new byte[3, 3]
            {
                { 10, 30, 60 },
                { 90, 120, 150 },
                { 180, 210, 240 }
            };
            filter.Add(new Grayscale(.3, .59, .11));
            filter.Add(new ErrorDiffusionToAdjacentNeighbors(
                           new int[3][] {
                new int[2] {
                    5, 3
                },
                new int[5] {
                    2, 4, 5, 4, 2
                },
                new int[3] {
                    2, 3, 2
                }
            }
                           ));
            ImgFinal.Image = filter.Apply(minhaImagem);
        }
コード例 #6
0
        public static IEnumerable <Bitmap> GetInnerBlobObjects(this Bitmap iBitmap)
        {
            var             biggestBlobObject = GetBlobObject(iBitmap);
            Bitmap          grayImage         = biggestBlobObject.ToGrayscale();
            FiltersSequence sq = new FiltersSequence();

            sq.Add(new BradleyLocalThresholding());
            sq.Add(new Invert());
            Bitmap revorsIMage = sq.Apply(grayImage);
            var    innerBlobs  = revorsIMage.GetBlobObjects(new Size(2, 2));
            int    rCounter    = innerBlobs.Count();

            return(innerBlobs);
            //Edges filter1 = new Edges();
            //var test3= filter1.Apply(biggestBlobObject);

            //HomogenityEdgeDetector filter2 = new HomogenityEdgeDetector();
            //var tesdasd2 = filter2.Apply(qwe);

            //DifferenceEdgeDetector filter3 = new DifferenceEdgeDetector();
            //var tesdasd322 = filter3.Apply(qwe);

            //SobelEdgeDetector filter4 = new SobelEdgeDetector();
            //var tesdasd3asdas22 = filter4.Apply(qwe);

            //CannyEdgeDetector filter45 = new CannyEdgeDetector( );
            //var tesdasd22 = filter45.Apply(qwe);
        }
コード例 #7
0
        private FiltersSequence commonSeq, extractCodeSeq, extractQRCodeSeqForRedTicket, extractQRCodeSeqForBlueTicket, qrReturnSeq;                          //Commonly filter sequence to be used

        public TicketRecognizer()
        {
            commonSeq      = new FiltersSequence();
            extractCodeSeq = new FiltersSequence();
            extractQRCodeSeqForRedTicket  = new FiltersSequence();
            extractQRCodeSeqForBlueTicket = new FiltersSequence();
            qrReturnSeq = new FiltersSequence();
            commonSeq.Add(new GrayscaleBT709());                            //灰度化
            commonSeq.Add(new SISThreshold());                              //二值化
            commonSeq.Add(new Invert());
            extractCodeSeq.Add(new Mean());                                 //均值滤波
            //extractCodeSeq.Add(new Invert());                            //黑白翻转
            extractQRCodeSeqForRedTicket.Add(new GrayscaleBT709());
            extractQRCodeSeqForRedTicket.Add(new DifferenceEdgeDetector());
            extractQRCodeSeqForRedTicket.Add(new SISThreshold());
            extractQRCodeSeqForRedTicket.Add(new Dilatation());


            extractQRCodeSeqForBlueTicket.Add(new GrayscaleBT709());
            extractQRCodeSeqForBlueTicket.Add(new DifferenceEdgeDetector());
            extractQRCodeSeqForBlueTicket.Add(new SISThreshold());
            extractQRCodeSeqForBlueTicket.Add(new Dilatation());

            qrReturnSeq.Add(new GrayscaleBT709());
            qrReturnSeq.Add(new Blur());
        }
コード例 #8
0
        private FiltersSequence commonSeq;              //Commonly filter sequence to be used
        /// <summary>
        /// Constructor
        /// </summary>
        public CardRecognizer()
        {
            //Initialize common filter sequence , this sequence generally will be applied
            commonSeq = new FiltersSequence();
            commonSeq.Add(Grayscale.CommonAlgorithms.BT709);
            commonSeq.Add(new BradleyLocalThresholding());
            commonSeq.Add(new DifferenceEdgeDetector());


            //Load Templates From Resources ,
            //Templates will be used for template matching
            j        = miranda.ui.Properties.Resources.J;
            k        = miranda.ui.Properties.Resources.K;
            q        = miranda.ui.Properties.Resources.Q;
            clubs    = miranda.ui.Properties.Resources.Clubs;
            diamonds = miranda.ui.Properties.Resources.Diamonds;
            spades   = miranda.ui.Properties.Resources.Spades;
            hearts   = miranda.ui.Properties.Resources.Hearts;


            try
            {
                _engine = new TesseractEngine(@"./tessdata", "rus", EngineMode.Default);
                //_engine.SetVariable("tessedit_char_whitelist", "$.,0123456789");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                Ex.Report(ex);
            }
        }
コード例 #9
0
        public static async Task <string> SaveNewPhoto(FileResult photo)
        {
            //Save in {App Directory}\img\{GUID}.jpg
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "img", Guid.NewGuid().ToString() + ".jpg");

            //Canceled
            if (photo == null)
            {
                return(null);
            }

            //Create img folder if needed
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }

            //Save the file to folder
            using (Stream stream = await photo.OpenReadAsync())
                using (Bitmap b = (Bitmap)ShimDrawing::System.Drawing.Image.FromStream(stream))
                    using (Stream img = File.OpenWrite(path))
                    {
                        FiltersSequence f = new FiltersSequence();
                        f.Add(new ResizeBilinear(800, (int)(800.0 * b.Height / b.Width)));

                        if (b.Height < b.Width)
                        {
                            f.Add(new RotateBilinear(-90));
                        }

                        f.Apply(ImageProcessor.Format(b)).Save(img, ShimDrawing::System.Drawing.Imaging.ImageFormat.Jpeg);
                    }

            return(path);
        }
コード例 #10
0
ファイル: ScanTest.cs プロジェクト: rrossenbg/vprint
        public static Bitmap ToGrayScale(this Bitmap image)
        {
            var seq = new FiltersSequence();

            seq.Add(Grayscale.CommonAlgorithms.BT709);  //First add  GrayScaling filter
            seq.Add(new OtsuThreshold());               //Then add binarization(thresholding) filter
            return(seq.Apply(image));                   // Apply filters on source image
        }
コード例 #11
0
        // Constructor
        public MotionDetector3( )
        {
            processingFilter1.Add(grayscaleFilter);
            processingFilter1.Add(pixellateFilter);

            processingFilter2.Add(differenceFilter);
            processingFilter2.Add(thresholdFilter);
            processingFilter2.Add(dilatationFilter);
        }
コード例 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            var source = pbSelectedPicture.Image as Bitmap;
            var seq    = new FiltersSequence();

            seq.Add(Grayscale.CommonAlgorithms.BT709); //First add  grayScaling filter
            seq.Add(new OtsuThreshold());              //Then add binarization(thresholding) filter
            var temp = seq.Apply(source);

            pbProcessedPicture.Image = temp;
        }
コード例 #13
0
        // Process max 200 frames (5 min) in 320x240 resolution. So 76KB memory per frame (grayscale). 1200 frames is max 93 MB of RAM (normally less because of area)
        private void processFilePart()
        {
            int nrofframes = imageStack.Length;
            int i;
            int sum;
            // create filters
            Morph morphFilter = new Morph(); // filter for adapting background

            morphFilter.SourcePercent = 0.8;
            Difference      differenceFilter = new Difference();      // filter for subtracting two frames
            Threshold       thresholdFilter  = new Threshold();       // filter for thresholding
            FiltersSequence filters          = new FiltersSequence(); // all filters in one

            filters.Add(morphFilter);
            filters.Add(differenceFilter);
            filters.Add(thresholdFilter);
            thresholdFilter.ThresholdValue = threshold;
            // Process here
            for (i = 0; i < nrofframes; i++)
            {
                // move background towards current frame
                morphFilter.OverlayImage = imageStack[i];
                Bitmap Temp = morphFilter.Apply(backgroundFrame);
                backgroundFrame = Temp.Clone(new Rectangle(0, 0, Temp.Width, Temp.Height), Temp.PixelFormat);
                Temp.Dispose();
                // apply rest of the filters
                differenceFilter.OverlayImage = imageStack[i];
                Bitmap Temp2 = filters.Apply(backgroundFrame);
                sum = 0;
                // Calculate sum of white pixels
                for (int j = 0; j < Temp2.Width; j++)
                {
                    for (int k = 0; k < Temp2.Height; k++)
                    {
                        if (Temp2.GetPixel(j, k) != Color.FromArgb(255, 0, 0, 0))
                        {
                            sum += 1;
                        }
                    }
                }
                Temp2.Dispose();
                if (sum > objectsize)
                {
                    tracker.addFrame(currentFrame);
                }
                currentFrame += 1;
            }
            // Discard Array
            for (i = 0; i < nrofframes; i++)
            {
                imageStack[i].Dispose();
            }
        }
コード例 #14
0
 private void InitFilters()
 {
     gsFilter     = new Grayscale(0.33, 0.33, 0.33);
     diffFilter   = new Difference();
     motionFilter = new FiltersSequence();
     motionFilter.Add(new Threshold(THRESHOLD));
     motionFilter.Add(new BlobsFiltering(MIN_BLOB, MIN_BLOB, MAX_BLOB, MAX_BLOB, true));
     morphFilter = new Morph();
     morphFilter.SourcePercent = MORPH_PERCENT;
     blobCount           = new BlobCounter();
     blobCount.MinHeight = MIN_BLOB;
     blobCount.MaxHeight = MAX_BLOB;
 }
コード例 #15
0
        private List <Win32.Point> PointOfScreenDifferences()
        {
            Bitmap castbmp = Win32.CaptureWindow(Wow);

            FiltersSequence processingFilter = new FiltersSequence();

            processingFilter.Add(new Grayscale(0.3725, 0.6154, 0.0121));
            processingFilter.Add(new Pixellate());
            processingFilter.Add(new Difference(background));
            processingFilter.Add(new Threshold(15));
            processingFilter.Add(new Erosion());

            var blobCounter = new BlobCounter();

            blobCounter.ProcessImage(processingFilter.Apply(castbmp));

            Rectangle[] brl = blobCounter.GetObjectsRectangles();
            Log.Information("Bobber imagescan brl: {brl}", brl.Length);
            List <Win32.Point> sdl = new List <Win32.Point>();

            foreach (Rectangle br in brl)
            {
                Win32.Point pt = new Win32.Point {
                    x = (br.Left + br.Left + br.Right) * 4 / 12, y = (br.Top + br.Bottom + br.Bottom) * 4 / 12
                };
                Win32.ClientToScreen(Wow, ref pt);
                if ((br.Right - br.Left) > 9 && (br.Bottom - br.Top) > 9)
                {
//                    Win32.Point pt = new Win32.Point { x= wowRectangle.X+(br.Left + br.Right) / 2, y= wowRectangle.Y+(br.Top+br.Bottom)/2 };
                    Log.Information("Bobber imagescan br: {bx},{by} - {w},{h}", pt.x, pt.y, (br.Right - br.Left), (br.Bottom - br.Top));
                    sdl.Add(pt);
//                } else {
//                    Log.Information("Bobber imagescan ignore br: {bx},{by} - {w},{h}", pt.x,pt.y, (br.Right-br.Left),(br.Bottom-br.Top));
                }
            }
            // debug

            /*
             * Bitmap bmpDst = new Bitmap(castbmp);
             * using (var g = Graphics.FromImage(bmpDst)) {
             *  foreach (var br in brl) {
             *      if ((br.Right - br.Left) > 11 && (br.Bottom - br.Top) > 11) {
             *          g.DrawRectangle(Pens.White, br);
             *      }
             *  }
             * }
             * bmpDst.Save("sc_"+DateTime.UtcNow.Ticks+".png", ImageFormat.Png);
             */

            return(sdl);
        }
コード例 #16
0
ファイル: CardRecognizer.cs プロジェクト: thehoneymad/Cards
        /// <summary>
        /// Constructor
        /// </summary>
        public CardRecognizer()
        {
            //Initialize common filter sequence , this sequence generally will be applied
            commonSeq = new FiltersSequence();
            commonSeq.Add(Grayscale.CommonAlgorithms.BT709);
            commonSeq.Add(new BradleyLocalThresholding());
            commonSeq.Add(new DifferenceEdgeDetector());


            //Load Templates From Resources ,
            //Templates will be used for template matching

            LoadResources();
        }
コード例 #17
0
ファイル: frmMain.cs プロジェクト: thquan99/DoAn_Bienso
//--------------------------------------------------------------------
        private void process_motion()
        {
            IFilter filt = new GrayscaleY();
            currentFrame = filt.Apply(currentFrame);
            backgroundFrame = filt.Apply(backgroundFrame);
            FiltersSequence filters = new FiltersSequence();
            Morph filt_morph = new Morph();
            filt_morph.OverlayImage = currentFrame;
            Bitmap tmp = filt_morph.Apply(backgroundFrame);
            filters.Add(new Difference(tmp));
            filters.Add(new Threshold(15));
            Bitmap tmp1 = filters.Apply(currentFrame);
            alarm = CalculateWhitePixels(tmp1);
        }
コード例 #18
0
        // Constructor
        public MotionDetector4( )
        {
            processingFilter1.Add(grayscaleFilter);
            processingFilter1.Add(pixellateFilter);

            // load numbers bitmaps
            Assembly assembly = this.GetType( ).Assembly;

            for (int i = 1; i <= 9; i++)
            {
                numbersBitmaps[i - 1] = new Bitmap(assembly.GetManifestResourceStream(
                                                       string.Format("motion.Resources.{0}.gif", i)));
            }
        }
コード例 #19
0
ファイル: SettingsForm.cs プロジェクト: c1kad14/poker-miranda
        private void btnCardRank_Click(object sender, EventArgs e)
        {
            var  image  = Bitmap.FromFile(tbFile.Text) as Bitmap;
            Crop crop   = new Crop(_settings.MyCardsRect);//TODO card identity
            var  source = crop.Apply(image);

            FiltersSequence seq = new FiltersSequence();

            seq.Add(Grayscale.CommonAlgorithms.BT709); //First add  grayScaling filter
            seq.Add(new OtsuThreshold());              //Then add binarization(thresholding) filter
            var temp = seq.Apply(source);              // Apply filters on source image


            BlobCounter extractor = new BlobCounter();

            extractor.FilterBlobs = true;
            extractor.MinWidth    = extractor.MinHeight = (int)_settings.MinCardSize;//TODO card size
            //extractor.MaxWidth = extractor.MaxHeight = 70;//TODO card size
            extractor.ProcessImage(temp);

            //Will be used transform(extract) cards on source image
            //QuadrilateralTransformation quadTransformer = new QuadrilateralTransformation();


            Bitmap cardImg = null;

            foreach (Blob blob in extractor.GetObjectsInformation())
            {
                cardImg = source.Clone(blob.Rectangle, PixelFormat.DontCare);
                break;
            }

            var r = _settings.CardRankRect;
            var f = new AreaSelectorForm(new Rectangle(r.X * 5, r.Y * 5, r.Width * 5, r.Height * 5));

            f.Text = "Select CardRankRect rect";

            f.SetImage(cardImg, 5);
            if (f.ShowDialog() == DialogResult.OK)
            {
                var newRect = new Rectangle(
                    (int)Math.Round(f.Rect.X / 5.0),
                    (int)Math.Round(f.Rect.Y / 5.0),
                    (int)Math.Round(f.Rect.Width / 5.0),
                    (int)Math.Round(f.Rect.Height / 5.0));
                lblCardRank.Text       = newRect.ToString();
                _settings.CardRankRect = newRect;
                AppSettingsManager.Save(_settings);
            }
        }
コード例 #20
0
        private void Tec1_Click(object sender, EventArgs e)
        {
            FiltersSequence filter = new FiltersSequence();

            byte[,] matrix = new byte[3, 3]
            {
                { 10, 30, 60 },
                { 90, 120, 150 },
                { 180, 210, 240 }
            };
            filter.Add(new Grayscale(.3, .59, .11));
            filter.Add(new OrderedDithering(matrix));
            ImgFinal.Image = filter.Apply(minhaImagem);
        }
コード例 #21
0
        // Constructor
        public MotionDetector4(String mac)
        {
            processingFilter1.Add(grayscaleFilter);
            processingFilter1.Add(pixellateFilter);
            this.mac  = mac;
            mDatabase = Database.getInstance();
            // load numbers bitmaps
            Assembly assembly = this.GetType().Assembly;

            for (int i = 1; i <= 9; i++)
            {
                numbersBitmaps[i - 1] = new Bitmap(assembly.GetManifestResourceStream(
                                                       string.Format("Server.Resources.{0}.gif", i)));
            }
        }
コード例 #22
0
ファイル: Form1.cs プロジェクト: sliplow/ObjectTracking
        /// <summary>
        /// Based off www.codeproject.com/Articles/10248/Motion-Detection-Algorithms
        /// </summary>
        /// <param name="prevImage"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        private Bitmap ThresholdImage(Bitmap prevImage, Bitmap image)
        {
            // create filter
            new MoveTowards(image).ApplyInPlace(prevImage);

            FiltersSequence processingFilter = new FiltersSequence();

            processingFilter.Add(new Difference(prevImage));
            processingFilter.Add(new Pixellate());
            processingFilter.Add(new Grayscale(0.2125, 0.7154, 0.0721));
            processingFilter.Add(new Threshold(45));

            // apply the filter

            return(processingFilter.Apply(image));
        }
コード例 #23
0
        // Constructor
        public MotionDetector4()
        {
            processingFilter1.Add(grayscaleFilter);
            processingFilter1.Add(pixellateFilter);

            // load numbers bitmaps
            Assembly assembly = this.GetType().Assembly;

            for (int i = 1; i <= 9; i++)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("TeboCam.Properties.Resources.{0}", "_" + i));

                numbersBitmaps[i - 1] = new Bitmap(assembly.GetManifestResourceStream(
                                                       string.Format("TeboCam.Resources.{0}", "_" + i)));
            }
        }
コード例 #24
0
ファイル: MotionDetector4.cs プロジェクト: zhchtao323/sp
        // Constructor
        public MotionDetector4()
        {
            processingFilter1.Add(grayscaleFilter);
            processingFilter1.Add(pixellateFilter);

            processingFilter2.Add(differenceFilter);
            processingFilter2.Add(thresholdFilter);

            // load numbers bitmaps
            //Assembly assembly = this.GetType().Assembly;

            //for (int i = 1; i <= 9; i++)
            //{
            //    numbersBitmaps[i - 1] = new Bitmap(assembly.GetManifestResourceStream(
            //        string.Format("motion.Resources.{0}.gif", i)));
            //}
        }
コード例 #25
0
        static void Main(string[] args)
        {
            try
            {
                string     path             = "D:\\HACK2015\\PICS";
                Bitmap     sourceImage      = AForge.Imaging.Image.FromFile(Path.Combine(path, "CAM1s.jpg"));
                Difference differenceFilter = new Difference(); //AForge.Imaging.Filters.Difference
                differenceFilter.OverlayImage = sourceImage;

                Bitmap sourceImg = AForge.Imaging.Image.FromFile(Path.Combine(path, "CAM1.jpg"));
                Bitmap tempImg   = sourceImg.Clone() as Bitmap;
                tempImg = differenceFilter.Apply(tempImg);
                FiltersSequence seq = new FiltersSequence();
                seq.Add(Grayscale.CommonAlgorithms.BT709);
                seq.Add(new OtsuThreshold());
                tempImg = seq.Apply(tempImg);
                tempImg.Save(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CAM1.jpg"));

                int objectCount = 0;

                BlobCounter blobCounter = new BlobCounter();
                blobCounter.FilterBlobs = true;
                blobCounter.MinHeight   = 60;
                blobCounter.MinWidth    = 40;
                blobCounter.ProcessImage(tempImg);
                Blob[] blobs = blobCounter.GetObjectsInformation();
                for (int i = 0; i < blobs.Length; i++)
                {
                    List <IntPoint>    edgePoints   = blobCounter.GetBlobsEdgePoints(blobs[i]);
                    List <IntPoint>    corners      = null;
                    SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
                    if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                    {
                        ++objectCount;
                    }
                }

                Console.WriteLine("No. of BLOBS: " + blobCounter.GetObjectsInformation().Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
コード例 #26
0
        public FormAForge()
        {
            InitializeComponent();

            context         = new FilterContext();
            filtersSequence = new FiltersSequence();
            filtersSequence.Add(new FilterVisualization(new GrayscaleY(), context));
            filtersSequence.Add(new FilterVisualization(new GaussianBlur(), context));
            filtersSequence.Add(new FilterVisualization(new ResizeBicubic(160, 120), context));

            filtersSequence.Add(new RemoveBackground(context));
            filtersSequence.Add(new Normalization(context));
            filtersSequence.Add(new Binarization(context));
            //filtersSequence.Add(new FilterVisualization(new Invert(), context));
            //filtersSequence.Add(new FilterVisualization(new Opening(), context));
            filtersSequence.Add(new Blobs(context));

            foreach (IFilter filter in filtersSequence)
            {
                FilterVisualization visualization = filter as FilterVisualization;
                if (visualization != null)
                {
                    flowLayoutPanelFilters.Controls.Add(visualization);
                }
            }
        }
コード例 #27
0
ファイル: Form1.cs プロジェクト: Slavedogg/PennX
        private void switchBandW(ref Bitmap tmpImg)
        {
            Bitmap orig  = tmpImg;
            Bitmap clone = new Bitmap(orig.Width, orig.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            using (Graphics gr = Graphics.FromImage(clone))
            {
                gr.DrawImage(orig, new Rectangle(0, 0, clone.Width, clone.Height));
            }

            FiltersSequence commonSeq = new FiltersSequence();

            commonSeq.Add(Grayscale.CommonAlgorithms.BT709);
            commonSeq.Add(new BradleyLocalThresholding());
            commonSeq.Add(new DifferenceEdgeDetector());

            tmpImg = commonSeq.Apply(clone);
        }
コード例 #28
0
ファイル: ImagesEx.cs プロジェクト: rrossenbg/vprint
        public static Bitmap ExtractBiggestBlob(this Bitmap image1, ref Rectangle rec)
        {
            lock (typeof(Lock_ExtractBiggestBlob))
            {
                FiltersSequence commonSeq = new FiltersSequence();
                commonSeq.Add(Grayscale.CommonAlgorithms.BT709);
                commonSeq.Add(new BradleyLocalThresholding());
                commonSeq.Add(new DifferenceEdgeDetector());

                using (Bitmap temp = commonSeq.Apply(image1))
                {
                    ExtractBiggestBlob extractor = new ExtractBiggestBlob();
                    var img = extractor.Apply(temp);
                    rec = new Rectangle(extractor.BlobPosition.X, extractor.BlobPosition.Y, img.Width, img.Height);
                    return(img);
                }
            }
        }
コード例 #29
0
        private void PreprocessParams_Changed(object sender, EventArgs e)
        {
            int   winSize             = (int)WindowSizeSelector.Value;
            float brightnessDiffLimit = (float)PixelBrightnessLimitSelector.Value;

            bool filterSmallBlobs = FilterSmallBlobsCheckBox.Checked;
            bool filterBigBlobs   = FilterBigBlobsCheckBox.Checked;

            bool filterSmallCoupled = FilterSmallCoupledCheckBox.Checked;
            bool filterBigCoupled   = FilterBigCoupledCheckBox.Checked;

            int minWidth = (int)MinWidthSelector.Value;
            int maxWidth = (int)MaxWidthSelector.Value;

            int minHeight = (int)MinHeightSelector.Value;
            int maxHeight = (int)MaxHeightSelector.Value;

            var filter = new FiltersSequence(
                Grayscale.CommonAlgorithms.RMY,
                new BradleyLocalThresholding()
            {
                WindowSize = winSize, PixelBrightnessDifferenceLimit = brightnessDiffLimit
            },
                new Invert()
                );

            if (filterSmallBlobs)
            {
                filter.Add(new BlobsFiltering()
                {
                    MinWidth = minWidth, MinHeight = minHeight, CoupledSizeFiltering = filterSmallCoupled
                });
            }

            if (filterBigBlobs)
            {
                filter.Add(new BlobsFiltering()
                {
                    MaxWidth = maxWidth, MaxHeight = maxHeight, CoupledSizeFiltering = filterBigCoupled
                });
            }

            m_preprocessingFilters = filter;
        }
コード例 #30
0
        void getROI(int x, int y)
        {
            if (pbox.Image == null)
            {
                return;
            }

            int originalWidth  = pbox.Image.Width;//原始尺寸
            int originalHeight = pbox.Image.Height;

            System.Reflection.PropertyInfo rectangleProperty = pbox.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(pbox, null);

            int currentWidth  = rectangle.Width;//缩放状态图片尺寸
            int currentHeight = rectangle.Height;

            double rate = (double)currentHeight / (double)originalHeight;                                  //缩放比率

            int black_left_width = (currentWidth == pbox.Width) ? 0 : (pbox.Width - currentWidth) / 2;     //左留白宽度
            int black_top_height = (currentHeight == pbox.Height) ? 0 : (pbox.Height - currentHeight) / 2; //上留白高度

            int zoom_x = x - black_left_width;                                                             //缩放图中鼠标坐标
            int zoom_y = y - black_top_height;

            double original_x = (double)zoom_x / rate;//原始图中鼠标坐标
            double original_y = (double)zoom_y / rate;

            roi.Add(Convert.ToInt32(original_x)); roi.Add(Convert.ToInt32(original_y));
            if (isRoi)
            {
                dicPoints.Add(mouseDownPoint, mouseUpPoint);
                tools = (Bitmap)AcquireRectangleImage(pbox.Image, new System.Drawing.Rectangle(roi[0], roi[1], roi[2] - roi[0], roi[3] - roi[1]));

                Bitmap cp = tools.Clone() as Bitmap; // 复制原始图像

                FiltersSequence seq = new FiltersSequence();
                seq.Add(Grayscale.CommonAlgorithms.BT709); // 添加灰度滤镜
                seq.Add(new OtsuThreshold());              // 添加二值化滤镜
                cp = seq.Apply(tools);                     // 应用滤镜
                pictureBox1.Image = cp;
                //roi.Clear();
            }
        }