예제 #1
0
        public Bitmap ToHSLFiltering(Bitmap Im)
        {
            AForge.Imaging.Filters.HSLFiltering Img = new HSLFiltering();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
예제 #2
0
        private String ContainBlue(Bitmap bitmap)
        {
            HSLFiltering blueFilter = new HSLFiltering();

            blueFilter.Hue        = new IntRange(150, 210);
            blueFilter.Saturation = new Range(0.3f, 1);
            blueFilter.Luminance  = new Range(0.20f, 0.8f);
            blueFilter.ApplyInPlace(bitmap);


            AForge.Imaging.BlobCounter blobCounterBlue = new AForge.Imaging.BlobCounter();
            blobCounterBlue.FilterBlobs  = true;
            blobCounterBlue.ObjectsOrder = ObjectsOrder.Area;
            blobCounterBlue.MinHeight    = 10;
            blobCounterBlue.MinWidth     = 10;
            blobCounterBlue.ProcessImage(bitmap);
            //capturedPhotoBlue.Source = (WriteableBitmap)bitmap;
            AForge.Imaging.Blob[] blobsBlue = blobCounterBlue.GetObjectsInformation();
            for (int iBlob = 0; iBlob < blobsBlue.Length; iBlob++)
            {
                for (int jBlob = iBlob + 1; jBlob < blobsBlue.Length; jBlob++)
                {
                    if ((Math.Abs(blobsBlue[iBlob].CenterOfGravity.X - blobsBlue[jBlob].CenterOfGravity.X) < blobsBlue[iBlob].Rectangle.Width / 2) &&
                        (Math.Abs(blobsBlue[iBlob].CenterOfGravity.Y - blobsBlue[jBlob].CenterOfGravity.Y) < 3 * blobsBlue[iBlob].Rectangle.Height) &&
                        (Math.Abs(blobsBlue[iBlob].Area - blobsBlue[jBlob].Area) < blobsBlue[iBlob].Area / 2))
                    {
                        //try { text_log.Text += "i" + iBlob + "j" + jBlob + "diff" + Math.Abs(blobsBlue[iBlob].CenterOfGravity.X - blobsBlue[jBlob].CenterOfGravity.X) + "w" + blobsBlue[iBlob].Rectangle.Width / 2; }
                        //catch (Exception ex) { text_log.Text = ex + ""; }
                        return("Blue");
                    }
                }
            }

            return("");
        }
예제 #3
0
        private String ContainGreen(Bitmap bitmap)
        {
            HSLFiltering filter = new HSLFiltering();

            // set color ranges to keep
            filter.Hue        = new IntRange(80, 150);
            filter.Saturation = new Range(0.4f, 1);
            filter.Luminance  = new Range(0.2f, 0.7f);
            filter.ApplyInPlace(bitmap);
            AForge.Imaging.BlobCounter blobCounterGreen = new AForge.Imaging.BlobCounter();
            blobCounterGreen.FilterBlobs  = true;
            blobCounterGreen.ObjectsOrder = ObjectsOrder.Area;
            blobCounterGreen.MinHeight    = 10;
            blobCounterGreen.MinWidth     = 10;
            blobCounterGreen.ProcessImage(bitmap);
            //capturedPhotoGreen.Source = (WriteableBitmap)bitmap;
            AForge.Imaging.Blob[] blobsGreen = blobCounterGreen.GetObjectsInformation();
            for (int iBlob = 0; iBlob < blobsGreen.Length; iBlob++)
            {
                for (int jBlob = iBlob + 1; jBlob < blobsGreen.Length; jBlob++)
                {
                    if ((Math.Abs(blobsGreen[iBlob].CenterOfGravity.X - blobsGreen[jBlob].CenterOfGravity.X) < blobsGreen[iBlob].Rectangle.Width / 2) &&
                        (Math.Abs(blobsGreen[iBlob].CenterOfGravity.Y - blobsGreen[jBlob].CenterOfGravity.Y) < 3 * blobsGreen[iBlob].Rectangle.Height) &&
                        (Math.Abs(blobsGreen[iBlob].Area - blobsGreen[jBlob].Area) < blobsGreen[iBlob].Area / 2))
                    {
                        //try { text_log.Text += "i" + iBlob + "j" + jBlob + "diff" + Math.Abs(blobsGreen[iBlob].CenterOfGravity.X - blobsGreen[jBlob].CenterOfGravity.X) + "w" + blobsGreen[iBlob].Rectangle.Width / 2; }
                        //catch (Exception ex) { text_log.Text = ex + ""; }
                        return("Green");
                    }
                }
            }
            //text_log.Text += "nG";
            return("");
        }
예제 #4
0
 public HSLFilteringFilter()
 {
     hSLFiltering            = new HSLFiltering();
     hSLFiltering.Hue        = new AForge.IntRange(330, 30);
     hSLFiltering.Luminance  = new AForge.Range(0, 1);
     hSLFiltering.Saturation = new AForge.Range(0, 1);
 }
예제 #5
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);
        }
예제 #6
0
파일: Camera.cs 프로젝트: zmaples/iSpy
 public void FilterChanged()
 {
     lock (_sync)
     {
         _filter = null;
     }
 }
예제 #7
0
        private static HSLFiltering GetFilterForBullishSignal()
        {
            HSLFiltering filter = new HSLFiltering();

            filter.Saturation = new Range(0.85f, 1f);
            filter.Luminance  = new Range(0.4f, 0.50f);
            filter.Hue        = new IntRange(180, 240);
            return(filter);
        }
예제 #8
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="HslBlobTracker"/> class.
        /// </summary>
        /// <param name="filter">The filter.</param>
        public HslBlobTracker(HSLFiltering filter)
        {
            this.filter         = filter;
            this.blobCounter    = new BlobCounter();
            this.trackingObject = new TrackingObject();

            blobCounter.CoupledSizeFiltering = false;
            blobCounter.FilterBlobs          = true;
        }
예제 #9
0
        private static HSLFiltering GetFilterForBearishSignal()
        {
            HSLFiltering filter = new HSLFiltering();

            filter.Saturation = new Range(0.98f, 1f);
            filter.Luminance  = new Range(0.48f, 0.52f);
            filter.Hue        = new IntRange(290, 310);
            return(filter);
        }
예제 #10
0
        // On Filters->HSL filtering
        /// <summary>
        /// HSL颜色空间中颜色过滤
        /// Hue :色调
        /// Saturation :对比度
        ///Luminance :亮度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hslFiltersItem_Click(object sender, System.EventArgs e)
        {
            HSLFiltering ff = new HSLFiltering(new IntRange(330, 30), new Range(0, 1), new Range(0, 1));

            //如果为false,则用指定的颜色填充区间内的像素,如果为true,则用指定的颜色填充区间外的像素(默认为true)
            ff.FillOutsideRange = false;
            ff.FillColor        = new HSL(330, 0.5f, 0.5f);
            ApplyFilter(ff);
            hslFiltersItem.Checked = true;
        }
예제 #11
0
        // Stel Filters af
        private void HSLFilter_White()
        {
            HSLFiltering filterWhite = new HSLFiltering
            {
                Hue        = new IntRange(20, 40),
                Saturation = new Range(0.09f, 1),
                Luminance  = new Range(0.8f, 1)
            };

            filterWhite.ApplyInPlace(ballBitmap);
        }
예제 #12
0
        private void colorOfPlayer(Bitmap bitmap)
        {
            HSLFiltering GreenFilter = new HSLFiltering();

            GreenFilter.Hue        = new IntRange(200, 250);
            GreenFilter.Saturation = new Range(0.5f, 1);
            GreenFilter.Luminance  = new Range(0.2f, 0.6f);
            GreenFilter.ApplyInPlace(bitmap);
            wbt             = (WriteableBitmap)bitmap;
            img2.Source     = wbt;
            img2.Visibility = Visibility.Visible;
            //    this.PictureBox.Source = (ImageSource)concatenate.Apply(this.img2);

            BlobCounter blobCounter = new AForge.Imaging.BlobCounter();

            blobCounter.ObjectsOrder = ObjectsOrder.Area;
            blobCounter.FilterBlobs  = true;
            blobCounter.MinHeight    = 10;
            blobCounter.MinWidth     = 10;
            blobCounter.ProcessImage(bitmap);
            Blob[]             blobs        = blobCounter.GetObjectsInformation();
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();


            try {
                for (int i = 0, n = blobs.Length; i < n; i++)
                {
                    List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                    AForge.Point    center;
                    float           radius;
                    // is circle ?
                    if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                    {
                        if ((blobs[i].Area < 17000) && (blobs[i].Area > 3000))
                        {
                            score = score + 2;
                        }
                        else if ((blobs[i].Area < 3000) && (blobs[i].Area > 1300))
                        {
                            score = score + 4;
                        }
                        else if (blobs[i].Area < 1300)
                        {
                            score = score + 6;
                        }
                    }
                }
            }catch (Exception eeeee)
            {
            }

            text_score.Text = "" + score;
        }
예제 #13
0
        private void HSLFilter_Pink()
        {
            // Adapt
            HSLFiltering filterBlue = new HSLFiltering
            {
                Hue        = new IntRange(220, 260),
                Saturation = new Range(0.6f, 1),
                Luminance  = new Range(0.2f, 0.8f)
            };

            filterBlue.ApplyInPlace(nullPointBitmap);
        }
예제 #14
0
파일: Hsl.cs 프로젝트: Rohail1/OOP-Project
        public static void Hsl_Setter(Bitmap video, int minHue, int maxHue, float minSat, float maxSat, float minLum, float maxLum)
        {
            //Create color filter
            HSLFiltering HslFilter = new HSLFiltering();

            //configre the filter
            HslFilter.Hue        = new IntRange(minHue, maxHue);
            HslFilter.Saturation = new Range(minSat, maxSat);
            HslFilter.Luminance  = new Range(minLum, maxLum);
            //apply color filter to the image
            HslFilter.ApplyInPlace(video);
        }
예제 #15
0
        private Boolean colorOfPlayer(Bitmap bitmap)
        {
            Boolean ok = false;

            HSLFiltering filterRed = new HSLFiltering();

            filterRed.Hue        = new IntRange(301, 9);   //red at night (334, 40)
            filterRed.Saturation = new Range(0.4f, 1);     //0.55
            filterRed.Luminance  = new Range(0.1f, 0.68f); //75
            filterRed.ApplyInPlace(bitmap);

            AForge.Imaging.BlobCounter blobCounterRed = new AForge.Imaging.BlobCounter();
            blobCounterRed.FilterBlobs  = true;
            blobCounterRed.ObjectsOrder = ObjectsOrder.Area;
            blobCounterRed.MinHeight    = 10;
            blobCounterRed.MinWidth     = 10;
            try { blobCounterRed.ProcessImage(bitmap); } catch (Exception es) { gameUpdate.Text = "filter"; }


            AForge.Imaging.Blob[] blobsRed = blobCounterRed.GetObjectsInformation();
            //Mean filter = new Mean();
            //// apply the filter
            //filter.ApplyInPlace(bitmap);
            bool fin = false;

            try
            {
                for (int iBlob = 0; iBlob < blobsRed.Length; iBlob++)
                {
                    for (int jBlob = iBlob + 1; jBlob < blobsRed.Length; jBlob++)
                    {
                        if ((Math.Abs(blobsRed[iBlob].CenterOfGravity.X - blobsRed[jBlob].CenterOfGravity.X) < blobsRed[iBlob].Rectangle.Width / 2) &&
                            (Math.Abs(blobsRed[iBlob].CenterOfGravity.Y - blobsRed[jBlob].CenterOfGravity.Y) < 3 * blobsRed[iBlob].Rectangle.Height) &&
                            (Math.Abs(blobsRed[iBlob].Area - blobsRed[jBlob].Area) < blobsRed[iBlob].Area / 2))
                        {
                            // gameUpdate.Text = "OK" + SharedInformation.myNumber + getPlayerNumberByColor("Red");
                            ortcExample.DoSendMessage(SharedInformation.myNumber + getPlayerNumberByColor("Red"));
                            fin = true;
                            return(true);
                        }
                    }
                    if (fin)
                    {
                        break;
                    }
                }
            }
            catch (Exception es) {
                gameUpdate.Text = "erreur";
            }
            return(ok);
        }
예제 #16
0
        private static Bitmap ApplyHslFilter(Bitmap bitmap)
        {
            var filter = new HSLFiltering
            {
                Hue        = new IntRange(335, 0),
                Saturation = new Range(0.6f, 1),
                Luminance  = new Range(0.1f, 1)
            };

            var filteredBitmap = filter.Apply(bitmap);

            return(filteredBitmap);
        }
예제 #17
0
        //For HSL Filtering
        private void HSLFiltering(Bitmap srcImage)
        {
            //Create filter
            HSLFiltering filter = new HSLFiltering();

            filter.Hue        = new IntRange(Hmin, Hmax);
            filter.Saturation = new Range(Smin, Smax);
            filter.Luminance  = new Range(Lmin, Lmax);

            //Apply the filter
            HSLImage          = filter.Apply(sourceImage);
            pictureBox2.Image = HSLImage;
        }
예제 #18
0
        private void process_button_Click(object sender, EventArgs e)
        {
            //changes are made here

            //HSL Filtering
            var hslFilter = new HSLFiltering();

            hslFilter.Hue        = new AForge.IntRange(10, 100);
            hslFilter.Saturation = new AForge.Range(0.1f, 1); //float number
            hslFilter.Luminance  = new AForge.Range(0, 1);
            var hsFilterOutput = hslFilter.Apply(_inputImage);

            pictureBoxOutput.Image = hsFilterOutput;
        }
예제 #19
0
        private void colorOfPlayer2(Bitmap bitmap2)
        {
            Bitmap bit2 = null;

            bit2 = bitmap2;
            bool         fin    = false;
            HSLFiltering filter = new HSLFiltering();

            // set color ranges to keep
            filter.Hue        = new IntRange(150, 210);
            filter.Saturation = new Range(0.3f, 1);
            filter.Luminance  = new Range(0.20f, 0.8f);
            filter.ApplyInPlace(bit2);
            AForge.Imaging.BlobCounter blobCounterGreen = new AForge.Imaging.BlobCounter();
            blobCounterGreen.FilterBlobs  = true;
            blobCounterGreen.ObjectsOrder = ObjectsOrder.Area;
            blobCounterGreen.MinHeight    = 10;
            blobCounterGreen.MinWidth     = 10;
            blobCounterGreen.ProcessImage(bit2);

            AForge.Imaging.Blob[] blobsGreen = blobCounterGreen.GetObjectsInformation();


            try
            {
                for (int iBlob = 0; iBlob < blobsGreen.Length; iBlob++)
                {
                    for (int jBlob = iBlob + 1; jBlob < blobsGreen.Length; jBlob++)
                    {
                        if ((Math.Abs(blobsGreen[iBlob].CenterOfGravity.X - blobsGreen[jBlob].CenterOfGravity.X) < blobsGreen[iBlob].Rectangle.Width / 2) &&
                            (Math.Abs(blobsGreen[iBlob].CenterOfGravity.Y - blobsGreen[jBlob].CenterOfGravity.Y) < 3 * blobsGreen[iBlob].Rectangle.Height) &&
                            (Math.Abs(blobsGreen[iBlob].Area - blobsGreen[jBlob].Area) < blobsGreen[iBlob].Area / 2))
                        {
                            //gameUpdate.Text = "OK" + SharedInformation.myNumber + getPlayerNumberByColor("Blue");
                            ortcExample.DoSendMessage(SharedInformation.myNumber + getPlayerNumberByColor("Blue"));
                            fin = true;
                            break;
                        }
                    }
                    if (fin)
                    {
                        break;
                    }
                }
            }
            catch (Exception es)
            {
                gameUpdate.Text = "erreur22";
            }
        }
예제 #20
0
        // U ovom zadatku koristi se aforge biblioteka za obradu slika u C# jeziku
        // Za zadanu sliku rjesenje je 5.
        // Rezultatna slika nalazi se na web adresi:
        // http://imageshack.us/scaled/landing/221/merged.png
        public static Bitmap FindObjects(System.Drawing.Bitmap image, int hueMin, int hueMax, float saturationMin, float saturationMax, float luminanceMin, float luminanceMax, int blobWidth, int blobHeight)
        {
            // HSL filter
            HSLFiltering filter = new HSLFiltering();

            // Zelimo zadrzati samo crvenu
            filter.Hue        = new IntRange(hueMin, hueMax);
            filter.Saturation = new Range(saturationMin, saturationMax);
            filter.Luminance  = new Range(luminanceMin, luminanceMax);

            // primjenimo filter
            filter.ApplyInPlace(image);

            // algoritam za trazenje nakupina (eng. blob)
            BlobCounterBase bc = new BlobCounter();

            // postavljamo filter za karakteristike nakupina koje trazimo
            bc.FilterBlobs = true;
            // Trazimo da budu odredene velicine kako bi uklonili sum na slici
            bc.MinWidth     = blobWidth;
            bc.MinHeight    = blobHeight;
            bc.ObjectsOrder = ObjectsOrder.Size;


            Bitmap redBlobs = image;

            bc.ProcessImage(redBlobs);

            //Trazimo crvene nakupine, tj crvene objekte na slici
            Blob[] blobs = bc.GetObjectsInformation();
            //Za zadanu sliku nasli smo ih pet, i spremljeni su u polje blobs, duzina polja je broj crvenih objekata na slici
            //Console.WriteLine(blobs.Length);
            bc.ExtractBlobsImage(redBlobs, blobs[0], true);

            //DODATNO: Radimo sliku samo sa pronadenim objektima, ovo nam sluzi samo kao provjera
            Merge  roses       = new Merge();
            Bitmap resultImage = blobs[0].Image.ToManagedImage();

            for (int j = 1; j < blobs.Length; j++)
            {
                bc.ExtractBlobsImage(redBlobs, blobs[j], true);
                roses.OverlayImage = blobs[j].Image.ToManagedImage();
                resultImage        = roses.Apply(resultImage);
            }
            //Odkomentirati sljedecu liniju, kako bi slika sa pronadenim objektima bila spremljena na disk, te se onda moze pregledati
            //resultImage.Save(@"C:\merged.jpg");
            return(resultImage);
        }
예제 #21
0
        private void hSLFiltering()
        // HSL Filtering
        {
            // Delare image
            Bitmap bmp = new Bitmap(pictureBox1.Image);
            // create filter
            HSLFiltering filter = new HSLFiltering();

            // set color ranges to keep
            filter.Hue        = new IntRange(335, 0);
            filter.Saturation = new Range(0.6f, 1);
            filter.Luminance  = new Range(0.1f, 1);
            // apply the filter
            filter.ApplyInPlace(bmp);
            pictureBox1.Image = bmp;
        }
예제 #22
0
        private void removeBackground(ref Bitmap image)
        {
            // create filter
            HSLFiltering filter = new HSLFiltering();

            // set color ranges to keep
            filter.Hue        = new IntRange(91, 42);
            filter.Saturation = new DoubleRange(0, 1);
            filter.Luminance  = new DoubleRange(0, 1);
            filter.FillColor  = new HSL(0, 0, 0.5);           // apply the filter
            filter.ApplyInPlace(image);

            Grayscale filterG = new Grayscale(0.2125, 0.7154, 0.0721);

            // apply the filter
            image = filterG.Apply(image);
        }
예제 #23
0
        // New frame event handler, which is invoked on each new available video frame
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Invoke((MethodInvoker) delegate()
            {
                optChose = comboBox2.SelectedIndex;
            });

            Bitmap bmp    = (Bitmap)eventArgs.Frame.Clone();
            Bitmap bmpPrc = (Bitmap)eventArgs.Frame.Clone();

            switch (optChose)
            {
            case 0:
                Grayscale     filter0   = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap        grayImage = filter0.Apply(bmpPrc);
                OtsuThreshold filter1   = new OtsuThreshold();
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter1.Apply(grayImage);
                break;

            case 1:
                Sepia filter2 = new Sepia();
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter2.Apply(bmpPrc);
                break;

            case 2:
                ChannelFiltering filter3 = new ChannelFiltering();
                filter3.Red       = new IntRange(0, 255);
                filter3.Green     = new IntRange(100, 255);
                filter3.Blue      = new IntRange(100, 255);
                pictureBox1.Image = bmp;
                pictureBox2.Image = filter3.Apply(bmpPrc);
                break;

            case 3:
                HSLFiltering filter4 = new HSLFiltering();
                filter4.Hue             = new IntRange(340, 20);
                filter4.UpdateLuminance = false;
                filter4.UpdateHue       = false;
                pictureBox1.Image       = bmp;
                pictureBox2.Image       = filter4.Apply(bmpPrc);
                break;
            }
        }
예제 #24
0
        public mFilterHSL(wDomain HueValue, wDomain SaturationValue, wDomain LuminanceValue, bool isOut, Color fillColor)
        {
            Hue       = HueValue;
            Sat       = SaturationValue;
            Lum       = LuminanceValue;
            IsOut     = isOut;
            FillColor = fillColor;


            BitmapType = mFilter.BitmapTypes.None;

            Effect = new HSLFiltering(new Accord.IntRange((int)Hue.T0, (int)Hue.T1), new Accord.Range((float)Sat.T0, (float)Sat.T1), new Accord.Range((float)Lum.T0, (float)Lum.T1));

            Effect.FillOutsideRange = IsOut;
            Effect.FillColor        = HSL.FromRGB(new RGB(FillColor));

            filter = Effect;
        }
예제 #25
0
        public void addcouleur(Bitmap bm)
        {
            if (LstZone.Count == 0 || LstZone[LstZone.Count - 1].ID != -1 && col != null)
            {
                int   w_i = bm.Width;
                int   h_i = bm.Height;
                int   w_c = imgReel.Width;
                int   h_c = imgReel.Height;
                float ord = ((float)w_i * (float)((float)this.col[0] / (float)w_c));
                float abs = ((float)h_i * (float)((float)this.col[1] / (float)h_c));
                this.col = null;
                int R = 0, G = 0, B = 0, A = 0;
                int count = 0;
                // Moyenne des pixels
                for (int i = (int)(ord - 1); i < (int)(ord + 1); i++)
                {
                    for (int j = (int)(abs - 1); j < (int)(abs + 1); j++)
                    {
                        count++;
                        Color c = bm.GetPixel(i, j);
                        R += c.R;
                        G += c.G;
                        B += c.B;
                        A += c.A;
                    }
                }
                RGB tmp  = new RGB(((byte)(R / count)), ((byte)(G / count)), ((byte)(B / count)), ((byte)(A / count)));
                HSL colo = HSL.FromRGB(tmp);
                Logger.GlobalLogger.debug("Couleur ajoutée : " + tmp.ToString() + " HLS : " + colo.Hue + " " + colo.Luminance + " " + colo.Saturation);

                HSLFiltering Filter = new HSLFiltering();
                Filter.Hue        = new IntRange((colo.Hue + 340) % 360, (colo.Hue + 20) % 360);
                Filter.Saturation = new Range(0.6f, 1f);
                Filter.Luminance  = new Range(0.1f, 1f);
                LstHslFiltering.Add(Filter);
                PositionZone ZoneTmp = new PositionZone();
                ZoneTmp.ID = -1;
                LstZone.Add(ZoneTmp);
                MessageBox.Show("Ajouter une zone de dépose avec le click milieu");
            }
        }
예제 #26
0
        private Bitmap hslImage(String path)
        {
            try
            {
                Bitmap image = new Bitmap(path);

                HSLFiltering filter = new HSLFiltering();

                //filter.Hue = new AForge.IntRange(335,0);
                filter.UpdateHue  = false;
                filter.Luminance  = new AForge.Range(0.4f, 1);
                filter.Saturation = new AForge.Range(0.6f, 1);

                image = filter.Apply(image);
                return(image);
            }
            catch (Exception ex)
            {
                throw new Exception("Deu erro na conversão");
            }
        }
예제 #27
0
        public String ContainRed(Bitmap bitmap)
        {
            HSLFiltering filterRed = new HSLFiltering();

            filterRed.Hue        = new IntRange(301, 9);   //red at night (334, 40)
            filterRed.Saturation = new Range(0.4f, 1);     //0.55
            filterRed.Luminance  = new Range(0.1f, 0.68f); //75
            filterRed.ApplyInPlace(bitmap);

            AForge.Imaging.BlobCounter blobCounterRed = new AForge.Imaging.BlobCounter();
            blobCounterRed.FilterBlobs  = true;
            blobCounterRed.ObjectsOrder = ObjectsOrder.Area;
            blobCounterRed.MinHeight    = 10;
            blobCounterRed.MinWidth     = 10;
            blobCounterRed.ProcessImage(bitmap);

            AForge.Imaging.Blob[] blobsRed = blobCounterRed.GetObjectsInformation();
            //capturedPhotoRed.Source = (WriteableBitmap)bitmap;
            //Mean filter = new Mean();
            //// apply the filter
            //filter.ApplyInPlace(bitmap);
            for (int iBlob = 0; iBlob < blobsRed.Length; iBlob++)
            {
                for (int jBlob = iBlob + 1; jBlob < blobsRed.Length; jBlob++)
                {
                    if ((Math.Abs(blobsRed[iBlob].CenterOfGravity.X - blobsRed[jBlob].CenterOfGravity.X) < blobsRed[iBlob].Rectangle.Width / 2) &&
                        (Math.Abs(blobsRed[iBlob].CenterOfGravity.Y - blobsRed[jBlob].CenterOfGravity.Y) < 3 * blobsRed[iBlob].Rectangle.Height) &&
                        (Math.Abs(blobsRed[iBlob].Area - blobsRed[jBlob].Area) < blobsRed[iBlob].Area / 2))
                    {
                        //try { text_log.Text += "i" + iBlob + "j" + jBlob + "diff" + Math.Abs(blobsRed[iBlob].CenterOfGravity.X - blobsRed[jBlob].CenterOfGravity.X) + "w" + blobsRed[iBlob].Rectangle.Width / 2; }
                        //catch (Exception ex) { text_log.Text = ex + ""; }
                        return("red");
                    }
                }
            }
            return("");
        }
예제 #28
0
        public String ContainPurple(Bitmap bitmap)
        {
            HSLFiltering filter = new HSLFiltering();

            // set color ranges to keep
            filter.Hue        = new IntRange(220, 290);
            filter.Saturation = new Range(0.4f, 0.8f);
            filter.Luminance  = new Range(0.35f, 0.78f);
            filter.ApplyInPlace(bitmap);

            AForge.Imaging.BlobCounter blobCounterPutple = new AForge.Imaging.BlobCounter();
            blobCounterPutple.FilterBlobs  = true;
            blobCounterPutple.ObjectsOrder = ObjectsOrder.Area;
            blobCounterPutple.MinHeight    = 10;
            blobCounterPutple.MinWidth     = 10;
            blobCounterPutple.ProcessImage(bitmap);
            AForge.Imaging.Blob[] blobsPurple        = blobCounterPutple.GetObjectsInformation();
            SimpleShapeChecker    shapeCheckerPurple = new SimpleShapeChecker();

            //capturedPhotoBlue.Source = (WriteableBitmap)bitmap;
            for (int iBlob = 0; iBlob < blobsPurple.Length; iBlob++)
            {
                for (int jBlob = iBlob + 1; jBlob < blobsPurple.Length; jBlob++)
                {
                    if ((Math.Abs(blobsPurple[iBlob].CenterOfGravity.X - blobsPurple[jBlob].CenterOfGravity.X) < blobsPurple[iBlob].Rectangle.Width / 2) &&
                        (Math.Abs(blobsPurple[iBlob].CenterOfGravity.Y - blobsPurple[jBlob].CenterOfGravity.Y) < 3 * blobsPurple[iBlob].Rectangle.Height) &&
                        (Math.Abs(blobsPurple[iBlob].Area - blobsPurple[jBlob].Area) < blobsPurple[iBlob].Area / 2))
                    {
                        //try { text_log.Text += "i" + iBlob + "j" + jBlob + "diff" + Math.Abs(blobsPurple[iBlob].CenterOfGravity.X - blobsPurple[jBlob].CenterOfGravity.X) + "w" + blobsPurple[iBlob].Rectangle.Width / 2; }
                        //catch (Exception ex) { text_log.Text = ex + ""; }
                        return("Purple");
                    }
                }
            }
            return("");
        }
예제 #29
0
        void SensorFrameReady(AllFramesReadyEventArgs e)
        {
            // if the window is displayed, show the depth buffer image
            Bitmap mask = null;

            using (DepthImageFrame frame = e.OpenDepthImageFrame())
            {
                if (frame != null)
                {
                    _depthBitmap = CreateBitMapFromDepthFrame(frame);
                    ColorFiltering filter = new ColorFiltering();
                    filter.Red   = new IntRange(50, 150);
                    filter.Green = new IntRange(200, 255);
                    filter.Blue  = new IntRange(150, 255);
                    // apply the filter
                    _depthBitmap = AForge.Imaging.Image.Clone(_depthBitmap, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    mask         = filter.Apply(_depthBitmap);


                    Grayscale gray = new Grayscale(0.7, 0.3, 0.1);
                    mask = gray.Apply(mask);

                    Threshold threshold = new Threshold(100);
                    threshold.ApplyInPlace(mask);

                    Invert invert = new Invert();
                    invert.ApplyInPlace(mask);
                }
            }

            using (ColorImageFrame frame = e.OpenColorImageFrame())
            {
                if (frame != null)
                {
                    _bitmap = _drawBitmap = ImageToBitmap(frame);
                    if (mask != null)
                    {
                        ApplyMask subtract = new ApplyMask(mask);
                        _bitmap = subtract.Apply(_bitmap);
                    }

                    HSLFiltering hsl = new HSLFiltering(new IntRange(330, 30), new Range(0.5f, 1), new Range(0.1f, 1));
                    hsl.ApplyInPlace(_bitmap);

                    Grayscale gray = new Grayscale(1, 0.8, 0.8);
                    _bitmap = gray.Apply(_bitmap);


                    Mean meanFilter = new Mean();
                    meanFilter.ApplyInPlace(_bitmap);


                    BlobsFiltering blob = new BlobsFiltering();
                    blob.CoupledSizeFiltering = false;
                    blob.MinHeight            = 15;
                    blob.MinWidth             = blob.MinHeight;
                    blob.MaxHeight            = blob.MaxWidth = 300;
                    blob.ApplyInPlace(_bitmap);

                    // locate objects using blob counter
                    BlobCounter blobCounter = new BlobCounter();
                    blobCounter.ProcessImage(_bitmap);
                    Blob[] blobs = blobCounter.GetObjectsInformation();

                    Pen redPen    = new Pen(Color.Red, 2);
                    Pen greenPen  = new Pen(Color.Green, 2);
                    Pen purplePen = new Pen(Color.OrangeRed, 3);
                    Pen pen;
                    // check each object and draw circle around objects, which
                    // are recognized as circles
                    int    maxBlob     = -1;
                    double maxFullness = -1;
                    for (int i = 0, n = blobs.Length; i < n; i++)
                    {
                        float hw_ratio = (float)(blobs[i].Rectangle.Height) / blobs[i].Rectangle.Width;

                        if (hw_ratio > 0.65 && hw_ratio < 1.5 && blobs[i].Area > 200 && blobs[i].Fullness > 0.35)
                        {
                            if (blobs[i].Area > maxFullness)
                            {
                                maxBlob     = i;
                                maxFullness = blobs[i].Area;
                            }
                        }
                    }

                    System.Console.WriteLine("MAX BLOB: " + maxBlob.ToString());


                    //draw to screen!
                    Grayscale gray2 = new Grayscale(0.2125, 0.7154, 0.072);
                    _drawBitmap = gray2.Apply(_drawBitmap);
                    _drawBitmap = AForge.Imaging.Image.Clone(_drawBitmap, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    Graphics g = Graphics.FromImage(_drawBitmap);

                    AForge.Point ballPos = new AForge.Point(-1, -1);
                    if (maxBlob >= 0)
                    {
                        ballPos = blobs[maxBlob].CenterOfGravity;
                    }
                    game.DrawGridAndScore(g, ballPos);

                    for (int i = 0, n = blobs.Length; i < n; i++)
                    {
                        float hw_ratio = (float)(blobs[i].Rectangle.Height) / blobs[i].Rectangle.Width;

                        if (hw_ratio > 0.65 && hw_ratio < 1.5 && blobs[i].Area > 200 && blobs[i].Fullness > 0.35)
                        {
                            AForge.Point center = blobs[i].CenterOfGravity;
                            if (maxBlob == i)
                            {
                                pen = purplePen;
                            }
                            else if (blobs[i].Fullness > 0.35)
                            {
                                continue;//pen = greenPen;
                            }
                            else
                            {
                                continue;// pen = redPen;
                            }
                            float radius = blobs[i].Rectangle.Width / 2;
                            g.DrawEllipse(pen,
                                          (int)(center.X - radius),
                                          (int)(center.Y - radius),
                                          (int)(radius * 2),
                                          (int)(radius * 2));
                            //g.DrawString(hw_ratio.ToString(), new Font("Arial", 16), new SolidBrush(Color.Yellow),
                            //   new System.Drawing.Point((int)center.X, (int)center.Y));
                        }
                    }

                    redPen.Dispose();
                    greenPen.Dispose();
                    purplePen.Dispose();
                    g.Dispose();

                    if (game.hasWon)
                    {
                        if (player == game.winningPlayer)
                        {
                            label1.Text = "You Won!!! Congrats :)";
                        }
                        else
                        {
                            label1.Text = "You Lost... :(";
                        }
                    }

                    this.Refresh();
                }
            }
        }
예제 #30
0
        private static Bitmap GetImageForFilter(HSLFiltering bearishFilter)
        {
            var bmp = DropOtherColors(bearishFilter);

            return(bmp);
        }