예제 #1
0
        public IEnumerable <Rectangle> GetAllRectangles(Bitmap img, Rectangle canny, Color color, int colorThreshold,
                                                        ContourAcceptance acceptance)
        {
            var imgFiltered = FilterImage(new Image <Bgr, byte>(img), new FilterParam(color, colorThreshold));

            var result = new List <Rectangle>();

            using (var contours = new VectorOfVectorOfPoint())
            {
                CvInvoke.FindContours(imgFiltered, contours, null, RetrType.List, ChainApproxMethod.LinkRuns);

                for (var i = 0; i < contours.Size; i++)
                {
                    var contour = contours[i];

                    if (!acceptance.ValideSize(contour.Size))
                    {
                        continue;
                    }

                    var area = CvInvoke.MinAreaRect(contour).MinAreaRect();

                    if (acceptance.ValideHeight(area.Height) && acceptance.ValideWidth(area.Width))
                    {
                        result.Add(new Rectangle(new Point(area.X, area.Y), new Size(area.Width, area.Height)));
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public bool HaveRectangle(Bitmap img, Rectangle canny, Color color, int colorThreshold,
                                  ContourAcceptance acceptance)
        {
            var config = new BasicAreaConfig
            {
                Area = new CaptureAreaConfig {
                    X = canny.X, Y = canny.Y, Width = canny.Width, Height = canny.Height
                },
                ContourAcceptance = new ContourAcceptanceConfig
                {
                    Height = acceptance.Height, HeightOffset = acceptance.HeightOffset,
                    Width  = acceptance.Width, WidthOffset = acceptance.WidthOffset,
                    Size   = acceptance.Size, SizeOffset = acceptance.SizeOffset
                },
                Color = new ColorConfig {
                    R = color.R, G = color.G, B = color.B, Seuil = colorThreshold
                }
            };

            return(HaveRectangle(img, config));
        }
예제 #3
0
        public Rectangle GetRectangle(Bitmap img, Rectangle canny, Color color, int colorThreshold, ContourAcceptance acceptance)
        {
            DebugWindow.SetImageStartFishingRaw((Bitmap)img.Clone());

            var imgFiltered = FilterImage(new Image <Bgr, byte>(img), new FilterParam(color, colorThreshold));

            DebugWindow.SetImageStartFishingFiltered(imgFiltered.ToBitmap());

            using (var contours = new VectorOfVectorOfPoint())
            {
                CvInvoke.FindContours(imgFiltered, contours, null, RetrType.List, ChainApproxMethod.LinkRuns);

                for (var i = 0; i < contours.Size; i++)
                {
                    var contour = contours[i];

                    if (!acceptance.ValideSize(contour.Size))
                    {
                        continue;
                    }

                    var area = CvInvoke.MinAreaRect(contour).MinAreaRect();

                    if (acceptance.ValideHeight(area.Height) && acceptance.ValideWidth(area.Width))
                    {
                        return(new Rectangle(new Point(area.X, area.Y), new Size(area.Width, area.Height)));
                    }
                }
            }

            return(Rectangle.Empty);
        }
예제 #4
0
        public void WaitRectangleColor(Rectangle canny, Color color, int colorThreshold, EventHandler <RectEventArgs> callback, int checkFrequency, ContourAcceptance acceptance)
        {
            while (true)
            {
                var rectangle = GetRectangle(canny, color, colorThreshold, acceptance);

                if (rectangle != Rectangle.Empty)
                {
                    callback(this, new RectEventArgs(rectangle));
                    return;
                }

                Thread.Sleep(checkFrequency);
            }
        }
예제 #5
0
 public Rectangle GetRectangle(Rectangle canny, Color color, int colorThreshold, ContourAcceptance acceptance)
 {
     return(GetRectangle(_screenHelper.ScreenArea(canny), canny, color, colorThreshold, acceptance));
 }