Ejemplo n.º 1
0
        public void CombineMaps()
        {
            var result = ImageTools.CombineMaps(new KeyValuePair <Image <Gray, byte>, Bgr>[] {
                new KeyValuePair <Image <Gray, byte>, Bgr>(new Image <Gray, byte>(Properties.Resources.Combine1), new Bgr(0, 0, 255)),
                new KeyValuePair <Image <Gray, byte>, Bgr>(new Image <Gray, byte>(Properties.Resources.Combine2), new Bgr(0, 255, 0)),
                new KeyValuePair <Image <Gray, byte>, Bgr>(new Image <Gray, byte>(Properties.Resources.Combine3), new Bgr(255, 0, 0)),
                new KeyValuePair <Image <Gray, byte>, Bgr>(new Image <Gray, byte>(Properties.Resources.Combine4), new Bgr(0, 255, 255)),
            });

            var expected = Properties.Resources.Combineresult;
            var actual   = result.ToBitmap();

            Assert.IsTrue(CompareBitmaps(expected, actual));
        }
Ejemplo n.º 2
0
        private void UpdateImages(string path)
        {
            if (String.IsNullOrWhiteSpace(path))
            {
                sourceImg = new Image <Bgr, byte>(100, 100);
            }
            else
            {
                sourceImg = new Image <Bgr, byte>(imageFilePath);
            }
            var hsvImg = sourceImg.Convert <Hsv, byte>();

            blueImg     = ImageTools.FilterColor(hsvImg, UserSettings.instance.blueMin, UserSettings.instance.blueMax);
            redImg      = ImageTools.FilterColor(hsvImg, UserSettings.instance.RedRange);
            greenImg    = ImageTools.FilterColor(hsvImg, UserSettings.instance.greenMin, UserSettings.instance.greenMax);
            yellowImg   = ImageTools.FilterColor(hsvImg, UserSettings.instance.yellowMin, UserSettings.instance.yellowMax);
            composedImg = ImageTools.CombineMaps(new List <KeyValuePair <Image <Gray, byte>, Bgr> >
            {
                new KeyValuePair <Image <Gray, byte>, Bgr>(blueImg, ImageTools.Colors.Blue),
                new KeyValuePair <Image <Gray, byte>, Bgr>(redImg, ImageTools.Colors.Red),
                new KeyValuePair <Image <Gray, byte>, Bgr>(greenImg, ImageTools.Colors.Green),
                new KeyValuePair <Image <Gray, byte>, Bgr>(yellowImg, ImageTools.Colors.Yellow),
            });

            if (operation == OperationType.Detection)
            {
                DetectionData ddb = ImageTools.DetectSquares(blueImg);
                DetectionData ddr = ImageTools.DetectSquares(redImg);
                DetectionData ddg = ImageTools.DetectSquares(greenImg);
                DetectionData ddy = ImageTools.DetectSquares(yellowImg);

                ddb.RemoveNoises();
                ddr.RemoveNoises();
                ddg.RemoveNoises();
                ddy.RemoveNoises();

                DetectionData common = new DetectionData(ddb);
                common.AddColor(ddr);
                common.AddColor(ddg);
                common.AddColor(ddy);

                composedImg = common.DrawDetection().Convert <Bgr, byte>();
                blueImg     = ddb.DrawDetection();
                redImg      = ddr.DrawDetection();
                greenImg    = ddg.DrawDetection();
                yellowImg   = ddy.DrawDetection();

                this.board = common.CreateBoard();
            }
        }
        private Image <Bgr, byte> Filter(Image <Bgr, byte> sourceImg, bool debugMode = false)
        {
            Image <Hsv, byte> img = sourceImg.Convert <Hsv, byte>();

            Image <Gray, byte> blue   = ImageTools.FilterColor(img, new Hsv(90, 90, 50), new Hsv(120, 255, 255), debugMode ? "Blue Debug Window" : "");
            Image <Gray, byte> green  = ImageTools.FilterColor(img, new Hsv(35, 70, 35), new Hsv(90, 255, 255), debugMode ? "Green Debug Window" : "");
            Image <Gray, byte> yellow = ImageTools.FilterColor(img, new Hsv(10, 70, 127), new Hsv(35, 255, 255), debugMode ? "Yellow Debug Window" : "");
            Image <Gray, byte> red    = ImageTools.FilterColor(
                img,
                new KeyValuePair <Hsv, Hsv>[] {
                new KeyValuePair <Hsv, Hsv>(new Hsv(0, 85, 80), new Hsv(12, 255, 255)),
                new KeyValuePair <Hsv, Hsv>(new Hsv(150, 85, 80), new Hsv(179, 255, 255))
            },
                debugMode ? "Red Debug Window" : ""
                );
            var colorDetection = ImageTools.CombineMaps(new List <KeyValuePair <Image <Gray, byte>, Bgr> > {
                new KeyValuePair <Image <Gray, byte>, Bgr>(blue, ImageTools.Colors.Blue),
                new KeyValuePair <Image <Gray, byte>, Bgr>(red, ImageTools.Colors.Red),
                new KeyValuePair <Image <Gray, byte>, Bgr>(green, ImageTools.Colors.Green),
                new KeyValuePair <Image <Gray, byte>, Bgr>(yellow, ImageTools.Colors.Yellow),
            });

            return(colorDetection);
        }