EdgeImage.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Emgu.CV;
  8. using Emgu.CV.Structure;
  9. using bbiwarg.Detectors.Fingers;
  10. using System.Diagnostics;
  11. using bbiwarg.Utility;
  12. using bbiwarg.Graphics;
  13. namespace bbiwarg.Images
  14. {
  15. class EdgeImage
  16. {
  17. public Image<Gray, Byte> Image { get; private set; }
  18. public EdgeImage(DepthImage depthImage, OutputImage outputImage)
  19. {
  20. Image<Gray, byte> dimg = depthImage.Image * (255.0f / (float)(depthImage.MaxDepth - depthImage.MinDepth));
  21. Image = dimg.Canny(100, 75, 3);
  22. // draw blue edges in outputImage
  23. outputImage.Image[2] = Image.ThresholdBinary(new Gray(0), new Gray(1)).Mul(255);
  24. }
  25. public EdgeImage(Image<Gray, Byte> edgeImage)
  26. {
  27. Image = edgeImage;
  28. }
  29. public bool isEdgeAt(Point point)
  30. {
  31. return isEdgeAt(point.X, point.Y);
  32. }
  33. public bool isEdgeAt(int x, int y)
  34. {
  35. return (Image.Data[y, x, 0] > 0);
  36. }
  37. public void removeFingerEdges(Finger finger)
  38. {
  39. Point[] polygon = finger.getPolygon();
  40. Image.FillConvexPoly(polygon, new Gray(0));
  41. }
  42. public EdgeImage copy()
  43. {
  44. return new EdgeImage(Image.Copy());
  45. }
  46. }
  47. }