FingerImage.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.Utility;
  10. using bbiwarg.Detectors.Fingers;
  11. namespace bbiwarg.Images
  12. {
  13. public enum FingerImageState {
  14. none = 0,
  15. possibleFingerSlice = 1,
  16. fingerSlice = 2,
  17. fingerDetected = 3,
  18. fingerTracked = 4
  19. }
  20. class FingerImage
  21. {
  22. private Image<Gray, byte> image;
  23. public FingerImage(int width, int height) {
  24. image = new Image<Gray, byte>(width, height);
  25. }
  26. public FingerImageState getStateAt(int x, int y) {
  27. return (FingerImageState)image.Data[y, x, 0];
  28. }
  29. public void drawFinger(Finger finger, FingerImageState state) {
  30. FingerSliceTrail trail = finger.SliceTrail;
  31. for (int i = 0; i < trail.NumSlices; i++) {
  32. drawLine(trail[i].Line, FingerImageState.fingerSlice);
  33. }
  34. drawLine(finger.LineSegment, state);
  35. }
  36. public void drawLine(Utility.LineSegment2D line, FingerImageState state)
  37. {
  38. image.Draw(new LineSegment2DF(line.P1, line.P2), new Gray((byte)state), 1);
  39. }
  40. }
  41. }