InputProvider.cs 2.3 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 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 start()
  20. {
  21. createDevice();
  22. registerHandles();
  23. device.Start();
  24. }
  25. public void stop()
  26. {
  27. device.Stop(true);
  28. }
  29. protected void createDevice()
  30. {
  31. handle = Iisu.Iisu.Context.CreateHandle();
  32. IDeviceConfiguration conf = createDeviceConfiguration();
  33. device = handle.InitializeDevice(conf);
  34. }
  35. protected virtual IDeviceConfiguration createDeviceConfiguration()
  36. {
  37. return handle.CreateDeviceConfiguration();
  38. }
  39. protected virtual void registerHandles()
  40. {
  41. ImageWidth = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Width").Value;
  42. ImageHeight = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Height").Value;
  43. depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
  44. confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
  45. device.EventManager.RegisterEventListener("DEVICE.DataFrame", new onNewFrameDelegate(onNewFrame));
  46. }
  47. private delegate void onNewFrameDelegate(String name, uint frameID);
  48. private void onNewFrame(String name, uint frameID)
  49. {
  50. device.UpdateFrame(false);
  51. IntPtr rawDepthData = depthImage.Value.Raw;
  52. IntPtr rawConfidenceData = confidenceImage.Value.Raw;
  53. device.ReleaseFrame();
  54. CurrentFrame = new InputFrame(CurrentFrameID, ImageWidth, ImageHeight, rawDepthData, rawConfidenceData);
  55. }
  56. }
  57. }