using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using bbiwarg.Utility; using Emgu.CV; using Emgu.CV.Structure; namespace bbiwarg.Output { class OutputImage : Image { public OutputImage(int width, int height) : base(width, height) { } public OutputImage(ImageSize size) : base(size.Width, size.Height) { } public Color getColotAt(int x, int y) { byte red = Data[y, x, 0]; byte green = Data[y, x, 1]; byte blue = Data[y, x, 2]; return Color.FromArgb(red, green, blue); } public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, Color color, int thickness = 1) { Draw(new Emgu.CV.Structure.LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(color), thickness); } public void drawContour(Contour contour, Color color, int thickness = 1) { Draw(contour, new Rgb(color), thickness); } public void drawPoints(Seq points, Color color, int thickness = 1) { Draw(points, new Rgb(color), thickness); } public void drawPixel(Point position, Color color) { Data[position.Y, position.X, 0] = color.R; Data[position.Y, position.X, 0] = color.G; Data[position.Y, position.X, 0] = color.B; } public void fillCircle(Point position, float radius, Color color) { Draw(new CircleF(position, radius), new Rgb(color), 0); } public void fillRectangle(Rectangle rect, Color color) { Draw(rect, new Rgb(color), -1); } public void drawRectangle(Rectangle rect, Color color, int thichness = 0) { Draw(rect, new Rgb(color), thichness); } public void drawText(Point position, String text, Color color) { MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1, 1); Draw(text, ref font, position, new Rgb(color)); } public void drawDefect(ConvexityDefect defect, Color pointColor, Color lineColor) { drawLineSegment(new Utility.LineSegment2D(defect.OuterShort, defect.Inner), lineColor); drawLineSegment(new Utility.LineSegment2D(defect.OuterLong, defect.Inner), lineColor); fillCircle(defect.Inner, 2, pointColor); fillCircle(defect.OuterShort, 2, pointColor); fillCircle(defect.OuterLong, 2, pointColor); } public void drawQuadrangleGrid(Quadrangle quad, Color borderColor, Color gridColor, int numRows, int numCols) { Vector2D a = quad.TopLeft; Vector2D b = quad.TopRight; Vector2D c = quad.BottomRight; Vector2D d = quad.BottomLeft; Vector2D relAB = (b - a) / numCols; Vector2D relDC = (c - d) / numCols; Vector2D relBC = (c - b) / numRows; Vector2D relAD = (d - a) / numRows; for (int i = 1; i < numCols; i++) { drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAB, d + i * relDC), gridColor); } for (int i = 1; i < numRows; i++) { drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAD, b + i * relBC), gridColor); } drawLineSegment(new bbiwarg.Utility.LineSegment2D(a, b), borderColor); drawLineSegment(new bbiwarg.Utility.LineSegment2D(b, c), borderColor); drawLineSegment(new bbiwarg.Utility.LineSegment2D(c, d), borderColor); drawLineSegment(new bbiwarg.Utility.LineSegment2D(d, a), borderColor); } public void drawBorder(Color color) { drawRectangle(new Rectangle(0, 0, Width, Height), color); } public void drawTouchGesture(List positions, Vector2D scale, float opacity = 1) { int numPositions = positions.Count; Color lineColor = Parameters.TouchEventVisualizerLineColor; Color pointColor = Parameters.TouchEventVisualizerPointColor; Color lineColorFaded = Color.FromArgb((int)(opacity * lineColor.R), (int)(opacity * lineColor.G), (int)(opacity * lineColor.B)); Color pointColorFaded = Color.FromArgb((int)(opacity * pointColor.R), (int)(opacity * pointColor.G), (int)(opacity * pointColor.B)); for (int i = 1; i < numPositions; i++) { drawLineSegment(new Utility.LineSegment2D(positions[i - 1].scale(scale), positions[i].scale(scale)), lineColorFaded); } Vector2D lastPos = positions[numPositions - 1].scale(scale); fillCircle(lastPos, 3, pointColorFaded); } public void drawImage(Image image, Color color) { if (color.R != 0) { if (color.R != byte.MaxValue) this[0] = this[0].Or(image.Mul((float)color.R / byte.MaxValue)); else this[0] = this[0].Or(image); } if (color.G != 0) { if (color.G != byte.MaxValue) this[1] = this[1].Or(image.Mul((float)color.G / byte.MaxValue)); else this[1] = this[1].Or(image); } if (color.B != 0) { if (color.B != byte.MaxValue) this[2] = this[2].Or(image.Mul((float)color.B / byte.MaxValue)); else this[2] = this[2].Or(image); } } } }