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.Graphics { class OutputImage { public Image Image { get; private set; } public OutputImage(int width, int height) { Image = new Image(width, height); } public Color getColotAt(int x, int y) { byte red = Image.Data[y, x, 0]; byte green = Image.Data[y, x, 1]; byte blue = Image.Data[y, x, 2]; return Color.FromArgb(red, green, blue); } public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, Color color, int thickness = 1) { Image.Draw(new Emgu.CV.Structure.LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(color), thickness); } public void drawContour(Contour contour, Color color, int thickness = 1) { Image.Draw(contour, new Rgb(color), thickness); } public void drawPoints(Seq points, Color color, int thickness = 1) { Image.Draw(points, new Rgb(color), thickness); } public void drawPixel(int x, int y, Color color) { Image.Data[y, x, 0] = color.R; Image.Data[y, x, 1] = color.G; Image.Data[y, x, 2] = color.B; } public void fillCircle(int x, int y, float radius, Color color) { Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0); } public void drawRectangle(int x, int y, int width, int height, Color color, int thichness = 0) { Image.Draw(new Rectangle(x, y, width, height), new Rgb(color), thichness); } public void drawText(int x, int y, String text, Color color) { MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1, 1); Image.Draw(text, ref font, new Point(x, y), new Rgb(color)); } public void drawImage(Image image, Color color) { if (color.R != 0) { if (color.R != byte.MaxValue) Image[0] = image.Mul((float)color.R / byte.MaxValue); else Image[0] = image; } if (color.G != 0) { if (color.G != byte.MaxValue) Image[1] = image.Mul((float)color.G / byte.MaxValue); else Image[1] = image; } if (color.B != 0) { if (color.B != byte.MaxValue) Image[2] = image.Mul((float)color.B / byte.MaxValue); else Image[2] = image; } } public void drawQuadrangleGrid(Quadrangle quad, Color borderColor, Color gridColor, int numRows, int numCols) { Vector2D a = quad.BottomLeft; Vector2D b = quad.TopLeft; Vector2D c = quad.TopRight; Vector2D d = quad.BottomRight; 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); } } }