EdgeImage.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.FingerDetection;
  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 Image<Gray, byte> RoughImage { get; private set; }
  19. public EdgeImage(DepthImage depthImage)
  20. {
  21. Image = (depthImage.Image * (255.0f / (float)(depthImage.MaxDepth - depthImage.MinDepth))).Canny(Constants.EdgeImageCannyStartThreshold, Constants.EdgeImageCannyLinkingThreshold, Constants.EdgeImageCannySize).ThresholdBinary(new Gray(0), new Gray(1));
  22. RoughImage = Image.Dilate(Constants.EdgeImageRoughNumDilationIterations);
  23. }
  24. public EdgeImage(Image<Gray, Byte> edgeImage)
  25. {
  26. Image = edgeImage;
  27. RoughImage = Image.Dilate(Constants.EdgeImageRoughNumDilationIterations);
  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 bool isRoughEdgeAt(Point point)
  38. {
  39. return isRoughEdgeAt(point.X, point.Y);
  40. }
  41. public bool isRoughEdgeAt(int x, int y)
  42. {
  43. return (RoughImage.Data[y, x, 0] > 0);
  44. }
  45. public void removeEdgesInsidePolygon(Point[] polygon)
  46. {
  47. Image.FillConvexPoly(polygon, new Gray(0));
  48. }
  49. public EdgeImage copy()
  50. {
  51. return new EdgeImage(Image.Copy());
  52. }
  53. public EdgeImage getRoughEdgeImage(int numDilateIterations) {
  54. return new EdgeImage(Image.Dilate(numDilateIterations));
  55. }
  56. }
  57. }