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); }
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)); }
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); }
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); } }
public Rectangle GetRectangle(Rectangle canny, Color color, int colorThreshold, ContourAcceptance acceptance) { return(GetRectangle(_screenHelper.ScreenArea(canny), canny, color, colorThreshold, acceptance)); }