IisuInputProvider.cs 4.6 KB

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