public override void Show(object value) { var tuple = (Tuple <Point2f, Point2f>)value; if (connectedComponent != null) { var validContour = connectedComponent.Contour != null; var boundingBox = validContour ? connectedComponent.Contour.Rect : new Rect(0, 0, 1, 1); var output = new IplImage(new Size(boundingBox.Width, boundingBox.Height), IplDepth.U8, 3); output.SetZero(); if (validContour) { DrawingHelper.DrawConnectedComponent(output, connectedComponent, new Point2f(-boundingBox.X, -boundingBox.Y)); if (tuple.Item1.X > 0 && tuple.Item1.Y > 0) { var projectedPoint = tuple.Item1 - new Point2f(boundingBox.X, boundingBox.Y); CV.Circle(output, new Point(projectedPoint), 3, Scalar.Rgb(255, 0, 0), -1); } if (tuple.Item2.X > 0 && tuple.Item2.Y > 0) { var projectedPoint = tuple.Item2 - new Point2f(boundingBox.X, boundingBox.Y); CV.Circle(output, new Point(projectedPoint), 3, Scalar.Rgb(0, 255, 0), -1); } } base.Show(output); } }
public override void Show(object value) { Point point; if (value is Point) { point = (Point)value; } else if (value is Point2f) { var point2f = (Point2f)value; point.X = float.IsNaN(point2f.X) ? -1 : (int)point2f.X; point.Y = float.IsNaN(point2f.Y) ? -1 : (int)point2f.Y; } else { var point2d = (Point2d)value; point.X = double.IsNaN(point2d.X) ? -1 : (int)point2d.X; point.Y = double.IsNaN(point2d.Y) ? -1 : (int)point2d.Y; } var image = visualizer.VisualizerImage; if (point.X < 0 || point.Y < 0 || point.X >= image.Width || point.Y >= image.Height) { points = null; } else if (tracking != TrackingMode.None) { if (points == null) { points = new Queue <Point>(1); polylines.Enqueue(points); } points.Enqueue(point); if (tracking == TrackingMode.Fixed) { var head = polylines.Peek(); head.Dequeue(); if (head.Count == 0) { polylines.Dequeue(); } } } if (polylines.Count > 0) { CV.PolyLine(image, polylines.Select(ps => ps.ToArray()).ToArray(), false, Scalar.Rgb(255, 0, 0), 2); } CV.Circle(image, point, 3, Scalar.Rgb(0, 255, 0), 3); if (tracking == TrackingMode.None) { polylines.Clear(); points = null; } }
public override void Show(object value) { var image = visualizer.VisualizerImage; var extremes = (Tuple <Point2f, Point2f>)value; CV.Circle(image, new Point(extremes.Item1), 3, Scalar.Rgb(255, 0, 0), -1); CV.Circle(image, new Point(extremes.Item2), 3, Scalar.Rgb(0, 255, 0), -1); }
public IObservable <IplImage> Process(IObservable <Tuple <IplImage, Point2f> > source) { return(source.Select(value => { var result = value.Item1.Clone(); var point = value.Item2; CV.Circle(result, new Point(point), Radius, Scalar.Rgb(255, 0, 0), Thickness); return result; })); }
public void EncodeImage_ReturnsSingleChannelMat() { var image = new IplImage(new Size(320, 240), IplDepth.U8, 3); image.SetZero(); CV.Circle(image, new Point(100, 100), 50, Scalar.Rgb(255, 0, 0)); var result = CV.EncodeImage(".jpg", image); Assert.AreEqual(1, result.Channels); }
internal static void Draw(IplImage image, KeyPointCollection keyPoints) { if (image != null) { var color = image.Channels == 1 ? Scalar.Real(255) : Scalar.Rgb(255, 0, 0); var radius = DefaultRadius * (int)Math.Ceiling(image.Height / DefaultHeight); foreach (var keyPoint in keyPoints) { CV.Circle(image, new Point(keyPoint), radius, color, -1); } } }
protected override Action <IplImage> GetRenderer() { var center = Center; var radius = Radius; var color = Color; var thickness = Thickness; var lineType = LineType; var shift = Shift; return(image => { CV.Circle(image, center, radius, color, thickness, lineType, shift); }); }
internal static void Draw(IplImage image, object value) { if (image != null) { var color = image.Channels == 1 ? Scalar.Real(255) : Scalar.Rgb(255, 0, 0); var thickness = DefaultThickness * (int)Math.Ceiling(image.Height / DefaultHeight); var circles = value as IEnumerable <Circle>; if (circles != null) { foreach (var circle in circles) { CV.Circle(image, new Point(circle.Center), (int)circle.Radius, color, thickness); } } else { var circle = (Circle)value; CV.Circle(image, new Point(circle.Center), (int)circle.Radius, color, thickness); } } }
public static void DrawConnectedComponent(IplImage image, ConnectedComponent component, Point2f offset) { if (component.Area <= 0) { return; } var centroid = component.Centroid + offset; var orientation = component.Orientation; var minorAxisOrientation = orientation + Math.PI / 2.0; var halfMajorAxis = component.MajorAxisLength * 0.5; var halfMinorAxis = component.MinorAxisLength * 0.5; var major1 = new Point((int)(centroid.X + halfMajorAxis * Math.Cos(orientation)), (int)(centroid.Y + halfMajorAxis * Math.Sin(orientation))); var major2 = new Point((int)(centroid.X - halfMajorAxis * Math.Cos(orientation)), (int)(centroid.Y - halfMajorAxis * Math.Sin(orientation))); var minor1 = new Point((int)(centroid.X + halfMinorAxis * Math.Cos(minorAxisOrientation)), (int)(centroid.Y + halfMinorAxis * Math.Sin(minorAxisOrientation))); var minor2 = new Point((int)(centroid.X - halfMinorAxis * Math.Cos(minorAxisOrientation)), (int)(centroid.Y - halfMinorAxis * Math.Sin(minorAxisOrientation))); if (component.Patch != null) { var target = image; var patch = component.Patch; var mask = patch.Channels == 1 ? patch : null; try { if (component.Contour != null) { var rect = component.Contour.Rect; mask = new IplImage(patch.Size, patch.Depth, 1); mask.SetZero(); CV.DrawContours(mask, component.Contour, Scalar.All(255), Scalar.All(0), 0, -1, LineFlags.Connected8, new Point(-rect.X, -rect.Y)); if (image.Width != rect.Width || image.Height != rect.Height) { target = image.GetSubRect(component.Contour.Rect); } } if (patch.Channels != target.Channels) { var conversion = patch.Channels > image.Channels ? ColorConversion.Bgr2Gray : ColorConversion.Gray2Bgr; patch = new IplImage(patch.Size, patch.Depth, image.Channels); CV.CvtColor(component.Patch, patch, conversion); } CV.Copy(patch, target, mask); } finally { if (patch != component.Patch) { patch.Dispose(); } if (mask != component.Patch) { mask.Dispose(); } if (target != image) { target.Dispose(); } } } else if (component.Contour != null) { CV.DrawContours(image, component.Contour, Scalar.All(255), Scalar.All(0), 0, -1, LineFlags.Connected8, new Point(offset)); } if (component.Contour != null) { CV.DrawContours(image, component.Contour, Scalar.Rgb(255, 0, 0), Scalar.Rgb(0, 0, 255), 0, 1, LineFlags.Connected8, new Point(offset)); } CV.Line(image, major1, major2, Scalar.Rgb(0, 0, 255)); CV.Line(image, minor1, minor2, Scalar.Rgb(255, 0, 0)); CV.Circle(image, new Point(centroid), 2, Scalar.Rgb(255, 0, 0), -1); }