IisuInputProvider.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Drawing;
  3. using System.Diagnostics;
  4. using System.Runtime.InteropServices;
  5. using Iisu;
  6. using MathNet.Numerics.LinearAlgebra.Single;
  7. namespace bbiwarg.InputProviders
  8. {
  9. class IisuInputProvider : IInputProvider
  10. {
  11. private IHandle handle;
  12. private IDevice device;
  13. private string moviePath;
  14. private bool active;
  15. private bool sourceIsMovie;
  16. //parameters
  17. private IParameterHandle<float> frameRate;
  18. private IParameterHandle<int> currentMovieFrame;
  19. private IParameterHandle<float> hfov;
  20. private IParameterHandle<float> vfov;
  21. private IParameterHandle<int> playStep;
  22. //data
  23. private IDataHandle<Iisu.Data.IImageData> depthImage;
  24. private IDataHandle<Iisu.Data.IImageData> confidenceImage;
  25. public IisuInputProvider(String moviePath = "")
  26. {
  27. if (moviePath.Length != 0)
  28. {
  29. this.moviePath = moviePath;
  30. sourceIsMovie = true;
  31. }
  32. else
  33. {
  34. sourceIsMovie = false;
  35. }
  36. active = false;
  37. }
  38. // control-methodes
  39. public void init()
  40. {
  41. handle = Iisu.Iisu.Context.CreateHandle();
  42. IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
  43. if (sourceIsMovie)
  44. conf.MoviePath = moviePath;
  45. device = handle.InitializeDevice(conf);
  46. // parameters
  47. if (sourceIsMovie)
  48. {
  49. //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
  50. device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // playMode = loop
  51. //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 2; // playMode = ping-pong
  52. playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
  53. currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
  54. }
  55. frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
  56. hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
  57. vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
  58. // events
  59. device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
  60. // data
  61. depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
  62. confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
  63. }
  64. private void onDeviceStatusChanged(string eventName, DeviceStatus status)
  65. {
  66. active = status.HasFlag(Iisu.DeviceStatus.Playing);
  67. }
  68. public void start()
  69. {
  70. device.Start();
  71. }
  72. public void stop()
  73. {
  74. device.Stop(true);
  75. }
  76. public void updateFrame()
  77. {
  78. device.UpdateFrame(true);
  79. }
  80. public void releaseFrame()
  81. {
  82. device.ReleaseFrame();
  83. }
  84. // Parameter-methodes
  85. public float getFrameRate()
  86. {
  87. return frameRate.Value;
  88. }
  89. public float getHFOV()
  90. {
  91. return hfov.Value;
  92. }
  93. public float getVFOV()
  94. {
  95. return vfov.Value;
  96. }
  97. public bool isActive()
  98. {
  99. return active;
  100. }
  101. // Data-methodes
  102. public InputFrame getInputFrame() {
  103. //depthData
  104. Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
  105. int width = (int)imageInfos.Width;
  106. int height = (int)imageInfos.Height;
  107. IntPtr rawDepthData = depthImage.Value.Raw;
  108. IntPtr rawConfidenceData = confidenceImage.Value.Raw;
  109. return new InputFrame(width, height, rawDepthData, rawConfidenceData);
  110. }
  111. // other
  112. public void pauseMovie()
  113. {
  114. if (sourceIsMovie)
  115. playStep.Value = 0;
  116. }
  117. public void unpauseMovie()
  118. {
  119. if (sourceIsMovie)
  120. playStep.Value = 1;
  121. }
  122. public int getCurrentMovieFrame()
  123. {
  124. if (sourceIsMovie)
  125. return currentMovieFrame.Value;
  126. return 0;
  127. }
  128. bool IInputProvider.sourceIsMovie()
  129. {
  130. return sourceIsMovie;
  131. }
  132. public void reversePlay()
  133. {
  134. if (sourceIsMovie)
  135. playStep.Value = -playStep.Value;
  136. }
  137. }
  138. }