OutputImage.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. using Emgu.CV;
  8. using Emgu.CV.Structure;
  9. namespace bbiwarg.Graphics
  10. {
  11. class OutputImage
  12. {
  13. public Image<Rgb, byte> Image { get; private set; }
  14. public OutputImage(int width, int height)
  15. {
  16. Image = new Image<Rgb, byte>(width, height);
  17. }
  18. public Color getColotAt(int x, int y)
  19. {
  20. byte red = Image.Data[y, x, 0];
  21. byte green = Image.Data[y, x, 1];
  22. byte blue = Image.Data[y, x, 2];
  23. return Color.FromArgb(red, green, blue);
  24. }
  25. public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, Color color, int thickness = 1)
  26. {
  27. Image.Draw(new LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(color), thickness);
  28. }
  29. public void drawContour(Contour<Point> contour, Color color, int thickness = 1)
  30. {
  31. Image.Draw(contour, new Rgb(color), thickness);
  32. }
  33. public void drawPoints(Seq<Point> points, Color color, int thickness = 1)
  34. {
  35. Image.Draw(points, new Rgb(color), thickness);
  36. }
  37. public void drawPixel(int x, int y, Color color)
  38. {
  39. Image.Data[y, x, 0] = color.R;
  40. Image.Data[y, x, 1] = color.G;
  41. Image.Data[y, x, 2] = color.B;
  42. }
  43. public void fillCircle(int x, int y, float radius, Color color)
  44. {
  45. Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0);
  46. }
  47. public void drawRectangle(int x, int y, int width, int height, Color color, int thichness = 0)
  48. {
  49. Image.Draw(new Rectangle(x, y, width, height), new Rgb(color), thichness);
  50. }
  51. public void drawText(int x, int y, String text, Color color) {
  52. MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1, 1);
  53. Image.Draw(text, ref font, new Point(x, y), new Rgb(color));
  54. }
  55. }
  56. }