예제 #1
0
        public void PerformPredatorActions()
        {
            cameraImage = Camera.Image;
            obstacleRectangle = DetectObstacle(greenFilter, cameraImage, new Vector2(35), ref greenColourBitmap);
            preyRectangle = DetectObstacle(redFilter, cameraImage, new Vector2(10), ref redColourBitmap);
            wallLineRectangle = DetectObstacle(whiteFilter, cameraImage, new Vector2(100, 0), ref whiteColourBitmap);
            redColourBitmap = ConvertImageFormat(redColourBitmap);
            redColourBitmap = ApplyColour(redColourBitmap, cameraImage, System.Drawing.Color.Red);
            greenColourBitmap = ConvertImageFormat(greenColourBitmap);
            greenColourBitmap = ApplyColour(greenColourBitmap, cameraImage, System.Drawing.Color.LightGreen);
            whiteColourBitmap = ApplyColour(whiteColourBitmap, cameraImage, System.Drawing.Color.Cyan);
            whiteColourBitmap = ConvertImageFormat(whiteColourBitmap);

            wallLeftPoint = GetPoint(whiteColourBitmap, wallLineRectangle.X, wallLineRectangle);
            wallRightPoint = GetPoint(whiteColourBitmap, wallLineRectangle.X+wallLineRectangle.Width-1, wallLineRectangle);
            System.Drawing.Point p = GetPoint(whiteColourBitmap, wallLineRectangle.X + wallLineRectangle.Width - (wallLineRectangle.Width/2), wallLineRectangle);
            AForge.Imaging.Filters.HistogramEqualization hFilter = new AForge.Imaging.Filters.HistogramEqualization();

            cameraImage = Greyscale(cameraImage);
            cameraImage = ConvertImageFormat(cameraImage);

            AForge.Imaging.Filters.SimplePosterization jFilter = new AForge.Imaging.Filters.SimplePosterization();
               // cameraImage = jFilter.Apply(cameraImage);

            AForge.Imaging.Filters.Merge mFilter = new AForge.Imaging.Filters.Merge(greenColourBitmap);

            Bitmap mergedColourImages = mFilter.Apply(whiteColourBitmap);

            mFilter = new AForge.Imaging.Filters.Merge(mergedColourImages);
            mergedColourImages = mFilter.Apply(redColourBitmap);

            mFilter = new AForge.Imaging.Filters.Merge(cameraImage);
            cameraImage = mFilter.Apply(mergedColourImages);

            //cameraImage = whiteColourBitmap;
            if (preyRectangle != new System.Drawing.Rectangle(0, 0, 0, 0))
                preyScreenPosition = preyRectangle;
            if (preyRectangle == new System.Drawing.Rectangle(0, 0, 0, 0) && searchingRotationCount < 8)
                trackingState = Tracking.Searching;
            else if (searchingRotationCount >= 8 && trackingState != Tracking.OnScreen)
                trackingState = Tracking.Roaming;
            else
                trackingState = Tracking.OnScreen;
            RobotCommands();
        }
예제 #2
0
        public Bitmap Process(Bitmap image)
        {
            Bitmap filteredImage = convertFormatTo32(image);

            if (filterLevel >= 0)
            {
                filteredImage = resize(filteredImage, ImageSize.Width, ImageSize.Height);
            }
            if (filterLevel >= 1)
            {

                if (ContrastStretch)
                {
                    AForge.Imaging.Filters.ContrastStretch stretcher = new AForge.Imaging.Filters.ContrastStretch();
                    filteredImage = stretcher.Apply(filteredImage);

                }

                if (Histogram)
                {
                    AForge.Imaging.Filters.HistogramEqualization histogrammer = new AForge.Imaging.Filters.HistogramEqualization();
                    filteredImage = histogrammer.Apply(filteredImage);

                }

                if (Gaussian)
                {
                    AForge.Imaging.Filters.GaussianBlur blurrer = new AForge.Imaging.Filters.GaussianBlur();
                    blurrer.Size = (int)GaussianStrength;
                    filteredImage = blurrer.Apply(filteredImage);
                }

                if (ContrastAdjustment)
                {
                    AForge.Imaging.Filters.ContrastCorrection contraster = new AForge.Imaging.Filters.ContrastCorrection();
                    contraster.Factor = (float)ContrastStrength;
                    filteredImage = contraster.Apply(filteredImage);
                }

                if (Greyscale)
                {
                    filteredImage = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(filteredImage);
                    //Greyscale downgrades format
                    // filteredImage  = convertFormatTo32(filteredImage.InternalBitmap);
                }
                if (Threshold)
                {
                    //filteredImage.InternalBitmap = convertFormatToGS(filteredImage.InternalBitmap);
                    AForge.Imaging.Filters.Threshold thresholder = new AForge.Imaging.Filters.Threshold();
                    thresholder.ThresholdValue = (int)(((double)ThresholdStrength / 10.0) * 255.0);
                    filteredImage = thresholder.Apply(filteredImage);

                }
                if (Bradley)
                {
                    AForge.Imaging.Filters.BradleyLocalThresholding bradlifier = new AForge.Imaging.Filters.BradleyLocalThresholding();

                    filteredImage = bradlifier.Apply(filteredImage);

                }
            }

            return filteredImage;
        }