InputProvider.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. ~InputProvider()
  20. {
  21. device.Stop(true);
  22. }
  23. public void initialize()
  24. {
  25. createDevice();
  26. registerHandles();
  27. device.Start();
  28. device.UpdateFrame(true);
  29. ImageWidth = (int)depthImage.Value.ImageInfos.Width;
  30. ImageHeight = (int)depthImage.Value.ImageInfos.Height;
  31. device.ReleaseFrame();
  32. }
  33. protected void createDevice()
  34. {
  35. handle = Iisu.Iisu.Context.CreateHandle();
  36. IDeviceConfiguration conf = createDeviceConfiguration();
  37. device = handle.InitializeDevice(conf);
  38. }
  39. protected virtual IDeviceConfiguration createDeviceConfiguration()
  40. {
  41. return handle.CreateDeviceConfiguration();
  42. }
  43. protected virtual void registerHandles()
  44. {
  45. depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
  46. confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
  47. }
  48. public InputFrame getInputFrame()
  49. {
  50. device.UpdateFrame(true);
  51. frameCounter++;
  52. IntPtr rawDepthData = depthImage.Value.Raw;
  53. IntPtr rawConfidenceData = confidenceImage.Value.Raw;
  54. device.ReleaseFrame();
  55. return new InputFrame(CurrentFrame, ImageWidth, ImageHeight, rawDepthData, rawConfidenceData);
  56. }
  57. }
  58. }