Example #1
0
        /// <summary>
        /// Nimmt HSV Bild, vergleicht mit eingegebener Farbe und gibt binaeres Graubild zurueck
        /// </summary>
        /// <param name="inImg">Eingabe HSV-bild</param>
        /// <param name="pcolor">Vergleichsfarbe</param>
        /// <param name="dHue">Farbtoleranz</param>
        /// <param name="dSaturation">Saettigungstoleranz</param>
        /// <param name="dValue">Helligeitstoleranz</param>
        /// <returns></returns>
        private Emgu.CV.Image <Gray, byte> thresholdHSVtoGray(Emgu.CV.Image <Hsv, byte> inImg, Hsv pcolor)
        {
            double lowH, lowS, lowV, highH, highS, highV;

            if (pcolor.Value < 15)
            {
                lowH = 0; highH = 179;
                lowS = 0; highS = 255;
            }
            else
            {
                lowH  = pcolor.Hue - dHue; //Math.Max(pcolor.Hue - dHue, 0);
                lowS  = Math.Max(pcolor.Satuation - dSaturation, 0);
                highH = pcolor.Hue + dHue; // Math.Min(pcolor.Hue + dHue, 179);
                highS = Math.Min(pcolor.Satuation + dSaturation, 255);
            }

            lowV  = Math.Max(pcolor.Value - dValue, 0);
            highV = Math.Min(pcolor.Value + dValue, 255);

            Image <Gray, byte> gray = new Image <Gray, byte>(inImg.Size);

            if (highH >= 180)
            {
                highH -= 180;
            }
            if (lowH < 0)
            {
                lowH += 180;
            }
            if (highH <= lowH)
            {
                Image <Gray, byte> gray1 = inImg.InRange(new Hsv(lowH, lowS, lowV), new Hsv(179, highS, highV));
                Image <Gray, byte> gray2 = inImg.InRange(new Hsv(0, lowS, lowV), new Hsv(highH, highS, highV));
                gray = gray1.Add(gray2);
            }
            else
            {
                gray = inImg.InRange(new Hsv(lowH, lowS, lowV), new Hsv(highH, highS, highV));
            }
            //Bildverbesserung
            gray.SmoothMedian(mediansize);

            return(gray);
        }
Example #2
0
        /// <summary>
        /// Process rocks in the image.
        /// </summary>
        private void ProcessSand()
        {
            // TODO: Make image be saved in MyDocs/Pictures.
            if (this.inputImage == null)
            {
                return;
            }

            Thread workerThread = new Thread(() =>
            {
                /*
                 * string path = @"C:\Users\POLYGONTeam\Documents\GitHub\Androbot\Androbot\Androbot\bin\Debug\Images\2D_20160728170358.PNG";
                 */
                //Emgu.CV.Image<Bgr, byte> inpImg = new Emgu.CV.Image<Bgr, byte>(this.inputImage);
                Emgu.CV.Image <Bgr, byte> inpImg = new Emgu.CV.Image <Bgr, byte>(inputImage);

                Emgu.CV.Image <Gray, byte> water = inpImg.InRange(new Bgr(0, 100, 0), new Bgr(255, 255, 255));
                //TODO: To check does we need mask?
                //water = water.Add(mask);
                //water._Dilate(1);

                // Create the blobs.
                Emgu.CV.Cvb.CvBlobs blobs = new Emgu.CV.Cvb.CvBlobs();
                // Create blob detector.
                Emgu.CV.Cvb.CvBlobDetector dtk = new Emgu.CV.Cvb.CvBlobDetector();
                // Detect blobs.
                uint state = dtk.Detect(water, blobs);

                foreach (Emgu.CV.Cvb.CvBlob blob in blobs.Values)
                {
                    //Console.WriteLine("Center: X:{0:F3} Y:{1:F3}", blob.Centroid.X, blob.Centroid.Y);
                    //Console.WriteLine("{0}", blob.Area);
                    if (blob.Area >= 4500 && blob.Area < 34465)
                    {
                        //Console.WriteLine("{0}", blob.Area);
                        inpImg.Draw(new CircleF(blob.Centroid, 5), new Bgr(Color.Red), 2);
                        inpImg.Draw(blob.BoundingBox, new Bgr(Color.Blue), 2);
                    }
                }

                if (this.outputImage != null)
                {
                    this.outputImage.Dispose();
                }
                // Dump the image.
                this.outputImage = inpImg.ToBitmap();
                // Show the nwe mage.
                this.pbMain.Image = this.FitImage(this.outputImage, this.pbMain.Size);
            });

            workerThread.Start();
        }