예제 #1
0
        public bool HaveRectangle(Bitmap img, BasicAreaConfig config)
        {
            var acceptance  = config.ContourAcceptance.ToContourAcceptance();
            var imgFiltered = FilterImage(new Image <Bgr, byte>(img), new FilterParam(config.Color.ToColor(), config.Color.Seuil));

            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(true);
                    }
                }
            }

            return(false);
        }
예제 #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));
        }