TouchImage.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Emgu.CV;
  7. using Emgu.CV.Structure;
  8. using bbiwarg.Utility;
  9. namespace bbiwarg.Images
  10. {
  11. public enum TouchImageState
  12. {
  13. none = 0,
  14. touchArea = 1,
  15. touchAreaMatched = 2,
  16. touchAreaStatusBar = 3,
  17. touchDetected = 4,
  18. touchTracked = 5
  19. }
  20. class TouchImage
  21. {
  22. private Image<Gray, byte> image;
  23. private List<Vector2D> oldTouches;
  24. public TouchImage(int width, int height)
  25. {
  26. image = new Image<Gray, byte>(width, height);
  27. oldTouches = new List<Vector2D>();
  28. }
  29. public void setTouchAt(int x, int y, TouchImageState tis)
  30. {
  31. image.Data[y, x, 0] = (byte)tis;
  32. int size = 5;
  33. if (tis == TouchImageState.touchTracked || tis == TouchImageState.touchDetected)
  34. {
  35. for (int i = x - size; i < x + size; i++)
  36. {
  37. for (int j = y - size; j < y + size; j++)
  38. {
  39. if (i >= 0 && j >= 0 && i <= image.Width && j <= image.Height && Math.Sqrt(((x - i) * (x - i)) + ((y - j) * (y - j))) <= size)
  40. {
  41. image.Data[j, i, 0] = (byte)tis;
  42. }
  43. }
  44. }
  45. }
  46. }
  47. public TouchImageState getStateAt(int x, int y)
  48. {
  49. return (TouchImageState)image.Data[y, x, 0];
  50. }
  51. }
  52. }