Ejemplo n.º 1
0
        private void CheckMotion()
        {
            blobCount.ProcessImage(frame_processed);

            /* Tryout drawing*/
            Rectangle[] rects = blobCount.GetObjectsRectangles();
            // create graphics object from initial image
            Graphics g = Graphics.FromImage(frame_c);

            // draw each rectangle
            using (Pen pen = new Pen(Color.Red, 1))
            {
                foreach (Rectangle rc in rects)
                {
                    g.DrawRectangle(pen, rc);

                    if ((rc.Width > 15) && (rc.Height > 15))
                    {
                        // here we can higligh large objects with something else
                    }
                }
            }
            g.Dispose();


            if (blobCount.GetObjectsRectangles().Length > 1)
            {
                SignalMotion();
            }
        }
Ejemplo n.º 2
0
        void stream_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            //создание стрима на весь экран
            Bitmap bmp = createBitmap(sender, eventArgs);


            //выделение желтого цвета
            EuclideanColorFiltering filter = new EuclideanColorFiltering();

            filter.CenterColor = new RGB(224, 209, 3); //желтый цвет
            filter.Radius      = 100;
            filter.ApplyInPlace(bmp);

            //Класс считает и извлекает отдельные объекты на изображениях
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.ProcessImage(bmp);

            Rectangle[] rects = blobCounter.GetObjectsRectangles(); //центр обьекта

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0) //обводить в квадарат
                {
                    //DrowPicture(rects, bmp);  // + pictureBox1.Image = bmp;

                    //  OR

                    MoveCoursor(recs.X, recs.Y); // + Form1_Shown -> Application.Exit();
                }
            }
            //pictureBox1.Image = bmp; //рисовать
        }
Ejemplo n.º 3
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            //Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
            //Grayscale griFiltre = new Grayscale(0.2, 0.2, 0.2);
            //Bitmap griImage = griFiltre.Apply(image);

            System.Drawing.Imaging.BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat);
            // grayscaling
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            // unlock image
            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            if (radioButton4.Checked)
            {
                //Tekli cisim Takibi Single Tracking--------

                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0];
                        Graphics  g          = Graphics.FromImage(image);
                        //Graphics g = pictureBox1.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                        }
                        //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);
                        //  g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        g.Dispose();

                        if (checkBox1.Checked)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //*****************************************

        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 2;
            blobCounter.MinHeight    = 2;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    griImage  = griFiltre.Apply(image);

            blobCounter.ProcessImage(griImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            pictureBox2.Image = griImage;
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    //Graphics g = Graphics.FromImage(image);
                    Graphics g = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }
                    //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                    objectX = objectRect.X + (objectRect.Width / 2);
                    objectY = objectRect.Y + (objectRect.Height / 2);
                    g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Process video and motion frames doing further post processing after
        /// performed motion detection.
        /// </summary>
        ///
        /// <param name="videoFrame">Original video frame.</param>
        /// <param name="motionFrame">Motion frame provided by motion detection
        /// algorithm (see <see cref="IMotionDetector"/>).</param>
        ///
        /// <remarks><para>Processes provided motion frame and counts number of separate
        /// objects, which size satisfies <see cref="MinObjectsWidth"/> and <see cref="MinObjectsHeight"/>
        /// properties. In the case if <see cref="HighlightMotionRegions"/> property is
        /// set to <see langword="true"/>, the found object are also highlighted on the
        /// original video frame.
        /// </para></remarks>
        ///
        public unsafe void ProcessFrame(UnmanagedImage videoFrame, UnmanagedImage motionFrame)
        {
            int width  = videoFrame.Width;
            int height = videoFrame.Height;

            if ((motionFrame.Width != width) || (motionFrame.Height != height))
            {
                return;
            }

            lock (blobCounter)
            {
                blobCounter.ProcessImage(motionFrame);
            }

            if (highlightMotionRegions)
            {
                // highlight each moving object
                Rectangle[] rects = blobCounter.GetObjectsRectangles();

                foreach (Rectangle rect in rects)
                {
                    DrawingHelper.Rectangle(videoFrame, rect, highlightColor);
                }
            }
        }
Ejemplo n.º 6
0
        public Bitmap showMotion(Bitmap originalImage, Bitmap motionImage)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.ProcessImage(motionImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();

            Graphics g = Graphics.FromImage(originalImage);

            foreach (Rectangle rc in rects)
            {
                rat1.checkRectangleProximity(rc);
                rat2.checkRectangleProximity(rc);
            }
            rat1.computeCenter();
            rat2.computeCenter();

            rat2.compareAndChange(rat1);

            rat1.drawTracker(g);
            rat2.drawTracker(g);

            g.Dispose();

            return(originalImage);
        }
Ejemplo n.º 7
0
        public Tuple <double, double> FindBlobLocation(Bitmap bmp)
        {
            Tuple <double, double> toRet = new Tuple <double, double>(0, 0);

            // Set up the detector with default parameters.
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight   = 5;
            blobCounter.MinWidth    = 5;
            blobCounter.MaxHeight   = 20;
            blobCounter.MaxHeight   = 20;

            blobCounter.ProcessImage(bmp);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();

            List <Rectangle> filteredRects = rects.Where(a => a.Location.X > eyeTracker.rectX && a.Location.X <(eyeTracker.rectX + eyeTracker.rectWidth) &&
                                                                                                               a.Location.Y> eyeTracker.rectY && a.Location.Y < eyeTracker.rectY + eyeTracker.rectHeight).ToList();

            if (filteredRects.Any())
            {
                toRet = new Tuple <double, double>(filteredRects.First().Location.X, filteredRects.First().Location.Y);
            }

            return(toRet);
        }
Ejemplo n.º 8
0
        private void CameraPanel_NewFrame(System.Drawing.Bitmap oBitmap)
        {
            #region 去除绿色以外其他色、绿色区域绘制边框
            Bitmap     objectImage = colorFilter.Apply(oBitmap);
            BitmapData objectData  = objectImage.LockBits(new Rectangle(0, 0, oBitmap.Width, oBitmap.Height),
                                                          ImageLockMode.ReadOnly, oBitmap.PixelFormat);
            UnmanagedImage grayImage = grayFilter.Apply(new UnmanagedImage(objectData));
            objectImage.UnlockBits(objectData);

            blobCounter1.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter1.GetObjectsRectangles();

            if (rects.Length > 0)
            {
                Rectangle objectRect = rects[0];
                Graphics  g          = Graphics.FromImage(oBitmap);
                using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(160, 255, 160), 3))
                {
                    g.DrawRectangle(pen, objectRect);
                }
                g.Dispose();
            }

            UpdateObjectPicture(objectImage);
            #endregion


            //#region 去除绿色以外其他色
            //Bitmap objectImage = colorFilter.Apply(oBitmap);
            //UpdateObjectPicture(objectImage);
            //#endregion

            //Bitmap objectImage = SobelEdgeFilter.Apply(oBitmap);
            //UpdateObjectPicture(objectImage);
        }
Ejemplo n.º 9
0
        private void Button_Belirt_Click(object sender, EventArgs e)
        {
            Bitmap image = (Bitmap)pictureBox1.Image.Clone();

            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red   = new IntRange(red, (int)numericUpDownRed.Value);
            colorFilter.Green = new IntRange(green, (int)numericUpDownGreen.Value);
            colorFilter.Blue  = new IntRange(blue, (int)numericUpDownBlue.Value);
            colorFilter.ApplyInPlace(image);

            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinHeight = 100;
            blobCounter.MinWidth  = 300;

            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);

            Rectangle[] rectangle = blobCounter.GetObjectsRectangles(); // bundan bir daha oluştur
            if (rectangle.Length > 0)                                   //içerde beyazları tespit etmek için
            {
                size = rectangle[0].Size;
                //MessageBox.Show(size.ToString());
                Rectangle objectt = rectangle[0];
                Graphics  graphic = Graphics.FromImage(image);
                using (Pen pen = new Pen(Color.Turquoise, 10))
                {
                    graphic.DrawRectangle(pen, objectt);
                }
                graphic.Dispose();
            }
            pictureBox2.Image = image;
        }
Ejemplo n.º 10
0
        new public Rectangle mostInterestingArea(System.Drawing.Image img_orig)
        {
            // http://stackoverflow.com/questions/2016406/converting-bitmap-pixelformats-in-c-sharp
            Bitmap img_middle = new Bitmap(img_orig);
            Bitmap img        = img_middle.Clone(new Rectangle(0, 0, img_middle.Width, img_middle.Height), System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            img_middle.Dispose();
            Bitmap bitmap = PreProcess((Bitmap)img);

            BlobCounter bc = new BlobCounter();

            bc.ProcessImage(bitmap);

            Rectangle[] objs = filteredObjects(bc.GetObjectsRectangles(), img);

            foreach (Rectangle obj in objs)
            {
                Console.WriteLine(obj);
            }

            Console.WriteLine("Blob Size: " + objs.Length);

            List <Size> _sizes = sizes(img);

            List <Rectangle> _areas = areas(img, _sizes);

            var ret = bestRuleOfThirdsBound(objs, _areas, img);

            img.Dispose();
            return(ret);
        }
Ejemplo n.º 11
0
        public static bool CheckLines(Bitmap image, Color filterColor)
        {
            EuclideanColorFiltering ColorFilter = new EuclideanColorFiltering();

            // set center colour and radius
            AForge.Imaging.RGB color = new AForge.Imaging.RGB(filterColor.R, filterColor.G, filterColor.B, filterColor.A);
            ColorFilter.CenterColor = color;
            ColorFilter.Radius      = 100;
            // Apply the filter
            ColorFilter.ApplyInPlace(image);

            // Define the Blob counter and use it!
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth    = 5;
            blobCounter.MinHeight   = 5;
            blobCounter.FilterBlobs = true;
            //blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);
            System.Drawing.Rectangle[] rects = blobCounter.GetObjectsRectangles();
            if (rects.Length > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 12
0
        private void detectObjectsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var img     = (Bitmap)currentImage.Clone();
            var showImg = (Bitmap)currentImage.Clone();

            // img = Grayscale.CommonAlgorithms.Y.Apply(img);
            img = new OtsuThreshold().Apply(img);
            img = new Erosion().Apply(img);
            img = new Invert().Apply(img);

            BlobCounter bc = new BlobCounter();

            bc.BackgroundThreshold = Color.Black;
            bc.ProcessImage(img);
            MessageBox.Show(String.Format("The image contains {0} objects.", bc.ObjectsCount));

            Rectangle  rect    = new Rectangle(0, 0, showImg.Width, showImg.Height);
            BitmapData bmpData = showImg.LockBits(rect, ImageLockMode.ReadWrite, showImg.PixelFormat);

            bc.GetObjectsRectangles().ToList().ForEach(i => {
                Drawing.Rectangle(bmpData, i, Color.GreenYellow);
            });

            showImg.UnlockBits(bmpData);

            pictureBox.Image = showImg;
        }
Ejemplo n.º 13
0
        private void hücreSayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            islem = new ExtractNormalizedRGBChannel(RGB.G).Apply(kaynak);
            islem = new OtsuThreshold().Apply(islem);
            islem = new Invert().Apply(islem);
            islem = new Opening().Apply(islem);

            BlobCounter bc = new BlobCounter();

            bc.FilterBlobs = false;
            bc.MinHeight   = 5;
            bc.MinWidth    = 5;
            bc.ProcessImage(islem);
            Rectangle[] rects = bc.GetObjectsRectangles();
            listBox1.Items.Add(rects.Length + " tane hücre var");

            Bitmap   cizim = new Bitmap(islem.Width, islem.Height);
            Graphics g     = Graphics.FromImage(cizim);

            g.DrawImage(islem, 0, 0);
            Pen cerceve = new Pen(Color.Red, 2);

            foreach (Rectangle rect in rects)
            {
                listBox1.Items.Add(rect.Location + " " + rect.Size);
                g.DrawRectangle(cerceve, rect);
            }
            g.Dispose();
            kaynakBox.Image = cizim;
        }
Ejemplo n.º 14
0
        private void scala(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 2;
            blobCounter.MinHeight    = 2;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage  = grayFilter.Apply(image);

            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    X = objectRect.X + (objectRect.Width / 2);
                    Y = objectRect.Y + (objectRect.Height / 2);
                    g.DrawString(X.ToString() + "X" + Y.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Get rectangles surrounding point clumps
        /// </summary>
        private static List <Rectangle> GetBoundingRecangles(Bitmap bitmapWithPoints)
        {
            var bitmapData = bitmapWithPoints.LockBits(
                new Rectangle(0, 0, bitmapWithPoints.Width, bitmapWithPoints.Height),
                ImageLockMode.ReadWrite, bitmapWithPoints.PixelFormat);


            var blobCounter = new BlobCounter
            {
                FilterBlobs = true,
                MinHeight   = 5,
                MinWidth    = 5
            };


            blobCounter.ProcessImage(bitmapData);
            var result = blobCounter.GetObjectsRectangles();

            if (result.Length == 0)
            {
                blobCounter = new BlobCounter
                {
                    FilterBlobs = true,
                    MinHeight   = 1,
                    MinWidth    = 1
                };
                blobCounter.ProcessImage(bitmapData);
                result = blobCounter.GetObjectsRectangles();
            }
            bitmapWithPoints.UnlockBits(bitmapData);
            return(RemoveNestedRectangles(new List <Rectangle>(result)));
        }
Ejemplo n.º 16
0
        private void getObjectsRectangles()
        // Get objects rectangles
        {
            // Declare image
            Bitmap      bmp         = new Bitmap(pictureBox1.Image);
            BlobCounter blobCounter = new BlobCounter(bmp);

            blobCounter.MinWidth    = 5;
            blobCounter.MinHeight   = 5;
            blobCounter.FilterBlobs = true;
            blobCounter.ProcessImage(bmp);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    foreach (Rectangle objectRect in rects)
                    {
                        Graphics g = Graphics.FromImage(bmp);

                        using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5))
                        {
                            g.DrawRectangle(pen, objectRect);
                        }

                        g.Dispose();
                        pictureBox1.Image = bmp;
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public static void  blob_setter(Bitmap video, Bitmap grayImage, int height, int width)
        {
            BlobCounter blobCounter = new BlobCounter();

            // configure it to filter out small objects
            blobCounter.MinWidth  = width;
            blobCounter.MinHeight = height;
            //       blobCounter.FilterBlobs = true;
            // set ordering - bigger objects go first
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            // locate blobs
            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = Graphics.FromImage(video);
                    using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 3))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 18
0
        public IScanImage Scan(ISource source, ScannerOptions options)
        {
            var image = new Bitmap(source.Take());

            // create grayscale filter (BT709)
            var filter     = new Grayscale(0.2125, 0.7154, 0.0721);
            var mBinarized = filter.Apply(image);

            // Binarize Picture.
            var bin = new Threshold(options.Threshold);

            bin.ApplyInPlace(mBinarized);

            // create filter
            var inv = new Invert();

            inv.ApplyInPlace(mBinarized);

            // create an instance of blob counter algorithm
            var bc = new BlobCounter {
                ObjectsOrder = ObjectsOrder.XY
            };

            bc.ProcessImage(mBinarized);
            var blobsRect = bc.GetObjectsRectangles();

            var b = Order(blobsRect);

            return(new ScanImage(image, b));
        }
Ejemplo n.º 19
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;



            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            foreach (Rectangle rect in rects)
            {
                Rectangle objectRect = rects[i];


                int objectX = objectRect.X + (objectRect.Width / 2);
                int objectY = objectRect.Y + (objectRect.Height / 2);


                a = objectX;
                b = objectY;
            }
        }
Ejemplo n.º 20
0
        void VideoSourcePlayerNewFrame(object sender, ref Bitmap image)
        {
            lock (this)
            {
                Bitmap    img_copy    = new Bitmap(image);
                Grayscale gray_filter = new Grayscale(0.2125, 0.7154, 0.0721);
                img_copy = gray_filter.Apply(img_copy);
                Threshold thresh = new Threshold(thresh_val);
                img_copy = thresh.Apply(img_copy);
                BlobCounter bc = new BlobCounter();
                bc.FilterBlobs = true;
                bc.MinHeight   = min_size_val;
                bc.MinWidth    = min_size_val;
                bc.MaxHeight   = min_size_val + 50;
                bc.MaxWidth    = min_size_val + 50;
                bc.ProcessImage(img_copy);
                Rectangle[] rects = bc.GetObjectsRectangles();

                Graphics g = videoSourcePlayer.CreateGraphics();
                using (Pen p = new Pen(Color.Red))
                {
                    foreach (Rectangle r in rects)
                    {
                        g.DrawRectangle(p, r);
                        g.DrawString("a", new Font("Consolas", 10), Brushes.Red, r.X, r.Y);
                    }
                }
                image = img_copy;
            }
        }
Ejemplo n.º 21
0
        public List <video.VideoProg.Cub> getImageColor(List <HSLFiltering> lst)
        {
            UnmanagedImage             tmpCol = null;
            List <video.VideoProg.Cub> tmp    = new List <video.VideoProg.Cub>();

            for (int i = 0; i < lst.Count; i++)
            {
                HSLFiltering Filter = lst[i];
                tmpCol = ImgColor.Clone();
                Filter.ApplyInPlace(tmpCol);

                // create blob counter and configure it
                BlobCounter blobCounter1 = new BlobCounter();
                blobCounter1.MinWidth     = 15;                // set minimum size of
                blobCounter1.MinHeight    = 15;                // objects we look for
                blobCounter1.FilterBlobs  = true;              // filter blobs by size
                blobCounter1.ObjectsOrder = ObjectsOrder.Size; // order found object by size

                blobCounter1.ProcessImage(tmpCol);
                //Rectangle[] rects = DeleteRectInterne( blobCounter1.GetObjectsRectangles());
                Rectangle[] rects = blobCounter1.GetObjectsRectangles();
                // draw rectangle around the biggest blob
                for (int j = 0; j < rects.Length; j++)
                {
                    if (rects[j] == null)
                    {
                        break;
                    }
                    tmp.Add(new video.VideoProg.Cub(rects[j], i));
                }
            }
            ImgColor = tmpCol;
            return(tmp);
        }
Ejemplo n.º 22
0
        private void button7_Click(object sender, EventArgs e)
        {
            Bitmap      images      = new Bitmap(pictureBox4.Image);
            Bitmap      İmage       = sobalEdgeDetection(images);
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight   = 10;
            blobCounter.MinWidth    = 10;
            blobCounter.MaxWidth    = 350;
            blobCounter.MaxHeight   = 350;
            blobCounter.ProcessImage(İmage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            if (rects.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("No rectangle found in image ");
            }
            else if (rects.Length > 1)
            {
                // get largets rect
                Console.WriteLine("Using largest rectangle found in image ");
                var r2 = rects.OrderByDescending(r => r.Height * r.Width).ToList();
                İmage = İmage.Clone(r2[1], İmage.PixelFormat);
            }
            else
            {
                Console.WriteLine("Huh? on image ");
            }
            pictureBox7.Image = İmage;
        }
Ejemplo n.º 23
0
        private void doWork(object o)
        {
            var data = o as Params;

            lock (work_lock)
            {
                using (var filteredImage = new Bitmap(data.Image))
                {
                    backgroundFilter.ApplyInPlace(filteredImage);

                    blobCounter.ProcessImage(filteredImage);
                }

                var rects = blobCounter.GetObjectsRectangles();

                int rectsCount = rects.Count();

                if (rectsCount == 0)
                {
                    return;
                }

                var result = new List <Bitmap>(rectsCount);

                foreach (Rectangle rect in rects)
                {
                    result.Add(data.Image.Crop(rect));
                }

                RaiseDetectedBlobs(result);
            }
        }
Ejemplo n.º 24
0
        private void cevreal(Bitmap image)// Algilanan rengi Çevrçevelemek veya hedeflemek için gerekli Method.
        {
            blobCounter.MinWidth     = 2;
            blobCounter.MinHeight    = 2;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage  = grayFilter.Apply(image);

            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }
                    objectX = objectRect.X + (objectRect.Width / 2);  //Dikdörtgenin Koordinatlari alınır.
                    objectY = objectRect.Y + (objectRect.Height / 2); //Dikdörtgenin Koordinatlari alınır.
                    g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 25
0
        private void sonYeni(object sender, NewFrameEventArgs eventArgs)
        {
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
            Bitmap video = (Bitmap)eventArgs.Frame.Clone();

            if (takip == 1)
            {
                ColorFiltering colorfilter = new ColorFiltering();
                colorfilter.Red   = new IntRange(Red, redMax);
                colorfilter.Green = new IntRange(Green, greenMax);
                colorfilter.Blue  = new IntRange(Blue, blueMax);
                colorfilter.ApplyInPlace(video);
                BlobCounter blobCounter = new BlobCounter();
                blobCounter.MinHeight    = 20;
                blobCounter.MinWidth     = 20;
                blobCounter.ObjectsOrder = ObjectsOrder.Size;
                blobCounter.ProcessImage(video);
                Rectangle[] rect = blobCounter.GetObjectsRectangles();
                if (rect.Length > 0)
                {
                    Rectangle obj = rect[0];
                    Graphics  gr  = Graphics.FromImage(video);
                    using (Pen pen = new Pen(Color.White, 3))
                    {
                        gr.DrawRectangle(pen, obj);
                    }
                    gr.Dispose();
                }
                pictureBox2.Image = video;
            }
        }
 public static Rectangle[] GetPossibleEternitySplinters(Bitmap bmp)
 {
     // Process input image
     EternitySplinterBlobCounter.ProcessImage(bmp);
     // Get information about detected objects
     Rectangle[] rectangles = EternitySplinterBlobCounter.GetObjectsRectangles();
     return(rectangles);
 }
Ejemplo n.º 27
0
        private Bitmap ProcessImage(Bitmap frame)
        {
            // convert the image to grayscale
            var grayConverter = new GrayscaleBT709();
            var grayFrame     = grayConverter.Apply(frame);

            // use a sobel edge detector to find color edges
            var edgeDetector = new SobelEdgeDetector();
            var edgeFrame    = edgeDetector.Apply(grayFrame);

            // threshold the edges
            var thresholdConverter = new Threshold(200);

            thresholdConverter.ApplyInPlace(edgeFrame);

            // use a blobcounter to find interesting shapes
            var detector = new BlobCounter()
            {
                FilterBlobs = true,
                MinWidth    = 25,
                MinHeight   = 25
            };

            detector.ProcessImage(edgeFrame);

            // find the circular shape
            var shapeDetector = new SimpleShapeChecker();
            var blobs         = detector.GetObjectsInformation();
            var circles       =
                from blob in blobs
                let edgePoints = detector.GetBlobsEdgePoints(blob)
                                 where shapeDetector.CheckShapeType(edgePoints) == ShapeType.Circle
                                 select blob;

            // show the traffic sign
            if (circles.Count() > 0)
            {
                var circleFrame = frame.Clone(circles.First().Rectangle, PixelFormat.DontCare);
                trafficSignBox.Image = circleFrame;
            }

            // highlight every circle in the image
            using (Graphics g = Graphics.FromImage(frame))
            {
                var rects = detector.GetObjectsRectangles();
                var pen   = new Pen(Color.Blue, 4);
                foreach (var circle in circles)
                {
                    g.DrawRectangle(pen, circle.Rectangle);
                }
            }

            // update picture boxes
            thresholdBox.Image = edgeFrame;

            return(frame);
        }
Ejemplo n.º 28
0
        private List <Rectangle> RgrectBobberCandidate(Bitmap imgBefore, Bitmap imgAfter)
        {
            var img         = XXX(imgBefore, imgAfter);
            var blobCounter = new BlobCounter();

            blobCounter.ProcessImage(img);

            return(blobCounter.GetObjectsRectangles().ToList());
        }
Ejemplo n.º 29
0
        private void cevreal(Bitmap image)
        {
            BlobCounter blobcounter = new BlobCounter();

            blobcounter.MinWidth     = 20;
            blobcounter.MinHeight    = 20;
            blobcounter.FilterBlobs  = true;
            blobcounter.ObjectsOrder = ObjectsOrder.Size;

            Grayscale grı      = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grıimage = grı.Apply(image);

            blobcounter.ProcessImage(grıimage);
            Rectangle[] rects = blobcounter.GetObjectsRectangles();

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle nesneRect = rects[0];
                    Graphics  g         = Graphics.FromImage(image);
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, nesneRect);
                    }

                    int nesneX = nesneRect.X + (nesneRect.Width / 2);
                    int nesneY = nesneRect.Y + (nesneRect.Height / 2);
                    g.DrawString(nesneX.ToString() + "X" + nesneY.ToString(), new Font("Arial", 50), Brushes.White, new System.Drawing.Point(0, 0));
                    g.Dispose();


                    if (nesneX > 0 && nesneX <= 213)
                    {
                        led = 1;
                    }
                    else if (nesneX > 213 && nesneX <= 426)
                    {
                        led = 2;
                    }
                    else if (nesneX > 426 && nesneX <= 640
                             )
                    {
                        led = 3;
                    }

                    if (gecici != led)
                    {
                        gecici = led;
                        if (serialPort1.IsOpen)
                        {
                            serialPort1.Write(led.ToString());
                        }
                    }
                }
            }
        }
        public static System.Drawing.Image AforgeAutoCrop(Bitmap selectedImage)
        {
            Bitmap autoCropImage = null;

            try
            {
                autoCropImage = selectedImage;
                // create grayscale filter (BT709)
                Grayscale filter    = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap    grayImage = filter.Apply(autoCropImage);
                // create instance of skew checker
                DocumentSkewChecker skewChecker = new DocumentSkewChecker();
                // get documents skew angle
                double angle = 0; // skewChecker.GetSkewAngle(grayImage);
                // create rotation filter
                RotateBilinear rotationFilter = new RotateBilinear(-angle);
                rotationFilter.FillColor = Color.White;
                // rotate image applying the filter
                Bitmap rotatedImage = rotationFilter.Apply(grayImage);
                new ContrastStretch().ApplyInPlace(rotatedImage);
                new Threshold(50).ApplyInPlace(rotatedImage);
                BlobCounter bc = new BlobCounter();
                bc.FilterBlobs = true;
                // bc.MinWidth = 500;
                //bc.MinHeight = 500;
                bc.ProcessImage(rotatedImage);
                Rectangle[] rects = bc.GetObjectsRectangles();

                if (rects.Length == 0)
                {
                    // CAN'T CROP
                }
                else if (rects.Length == 1)
                {
                    autoCropImage = autoCropImage.Clone(rects[0], autoCropImage.PixelFormat);;
                }
                else if (rects.Length > 1)
                {
                    // get largets rect
                    Console.WriteLine("Using largest rectangle found in image ");
                    var r2 = rects.OrderByDescending(r => r.Height * r.Width).ToList();
                    autoCropImage = autoCropImage.Clone(r2[0], autoCropImage.PixelFormat);
                }
                else
                {
                    Console.WriteLine("Huh? on image ");
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                //CAN'T CROP
            }

            return(autoCropImage);
        }