EdgeImage.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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;
  21. //rescale depthImage to [0,255] -> performance loss not worth (is already scaled to [0,200])
  22. /*double[] min, max;
  23. Point[] minLoc, maxLoc;
  24. dimg.MinMax(out min, out max, out minLoc, out maxLoc);
  25. double interval = max[0] - min[0];
  26. dimg = dimg.Convert(delegate(byte d) {return (byte) ((d/interval)*255);});*/
  27. Image = dimg.Canny(150, 100, 3);
  28. // draw blue edges in outputImage
  29. outputImage.Image[2] = Image.ThresholdBinary(new Gray(0), new Gray(1)).Mul(255);
  30. }
  31. public EdgeImage(Image<Gray, Byte> edgeImage)
  32. {
  33. Image = edgeImage;
  34. }
  35. public bool isEdgeAt(Point point)
  36. {
  37. return isEdgeAt(point.X, point.Y);
  38. }
  39. public bool isEdgeAt(int x, int y)
  40. {
  41. return (Image.Data[y, x, 0] > 0);
  42. }
  43. public void removeFingerEdges(Finger finger)
  44. {
  45. Point[] polygon = finger.getPolygon();
  46. Image.FillConvexPoly(polygon, new Gray(0));
  47. }
  48. public EdgeImage copy()
  49. {
  50. return new EdgeImage(Image.Copy());
  51. }
  52. }
  53. }