InputProvider.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 CurrentFrame { get { return frameCounter; }}
  14. protected int frameCounter = 0;
  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. }
  39. public void start() {
  40. device.Start();
  41. device.UpdateFrame(true);
  42. ImageWidth = (int)depthImage.Value.ImageInfos.Width;
  43. ImageHeight = (int)depthImage.Value.ImageInfos.Height;
  44. device.ReleaseFrame();
  45. }
  46. public void stop() {
  47. device.Stop(true);
  48. }
  49. public InputFrame getInputFrame()
  50. {
  51. device.UpdateFrame(true);
  52. frameCounter++;
  53. IntPtr rawDepthData = depthImage.Value.Raw;
  54. IntPtr rawConfidenceData = confidenceImage.Value.Raw;
  55. device.ReleaseFrame();
  56. return new InputFrame(CurrentFrame, ImageWidth, ImageHeight, rawDepthData, rawConfidenceData);
  57. }
  58. }
  59. }