InputProvider.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Iisu;
  7. namespace bbiwarg.InputProviders
  8. {
  9. class InputProvider
  10. {
  11. public int ImageWidth { get; private set; }
  12. public int ImageHeight { get; private set; }
  13. public virtual int CurrentFrameID { get { return device.FrameId; } }
  14. public InputFrame CurrentFrame { get; private set; }
  15. protected IHandle handle;
  16. protected IDevice device;
  17. protected IDataHandle<Iisu.Data.IImageData> depthImage;
  18. protected IDataHandle<Iisu.Data.IImageData> confidenceImage;
  19. public void initialize()
  20. {
  21. createDevice();
  22. registerHandles();
  23. }
  24. protected void createDevice()
  25. {
  26. handle = Iisu.Iisu.Context.CreateHandle();
  27. IDeviceConfiguration conf = createDeviceConfiguration();
  28. device = handle.InitializeDevice(conf);
  29. }
  30. protected virtual IDeviceConfiguration createDeviceConfiguration()
  31. {
  32. return handle.CreateDeviceConfiguration();
  33. }
  34. protected virtual void registerHandles()
  35. {
  36. depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
  37. confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
  38. device.EventManager.RegisterEventListener("DEVICE.DataFrame", new onNewFrameDelegate(onNewFrame));
  39. }
  40. private delegate void onNewFrameDelegate(String name, uint frameID);
  41. private void onNewFrame(String name, uint frameID)
  42. {
  43. device.UpdateFrame(false);
  44. IntPtr rawDepthData = depthImage.Value.Raw;
  45. IntPtr rawConfidenceData = confidenceImage.Value.Raw;
  46. device.ReleaseFrame();
  47. CurrentFrame = new InputFrame(CurrentFrameID, ImageWidth, ImageHeight, rawDepthData, rawConfidenceData);
  48. }
  49. public void start()
  50. {
  51. device.Start();
  52. device.UpdateFrame(true);
  53. ImageWidth = (int)depthImage.Value.ImageInfos.Width;
  54. ImageHeight = (int)depthImage.Value.ImageInfos.Height;
  55. device.ReleaseFrame();
  56. }
  57. public void stop()
  58. {
  59. device.Stop(true);
  60. }
  61. }
  62. }