InputProviderIntel.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using Emgu.CV;
  3. using Emgu.CV.Structure;
  4. using System.Threading;
  5. namespace BBIWARG.Input.InputProviding
  6. {
  7. class InputProviderIntel : MarshalByRefObject, IInputProvider
  8. {
  9. IntelCameraWrapper wrapper;
  10. public int CurrentFrameID
  11. {
  12. get;
  13. set;
  14. }
  15. public float FieldOfViewHorizontal
  16. {
  17. get;
  18. set;
  19. }
  20. public float FieldOfViewVertical
  21. {
  22. get;
  23. set;
  24. }
  25. public int ImageWidth
  26. {
  27. get { return 640; }
  28. }
  29. public int ImageHeight
  30. {
  31. get { return 480; }
  32. }
  33. public bool IsActive
  34. {
  35. get;
  36. set;
  37. }
  38. public event DeviceStartedEventHandler DeviceStartedEvent;
  39. public event NewFrameEventHandler NewFrameEvent;
  40. public UInt16 lowConfidenceValue;
  41. private AppDomain domain;
  42. public void initialize()
  43. {
  44. CurrentFrameID = 0;
  45. }
  46. public void start()
  47. {
  48. domain = System.AppDomain.CreateDomain("IntelSucks");
  49. wrapper = (IntelCameraWrapper) domain.CreateInstanceAndUnwrap(typeof(IntelCameraWrapper).Assembly.GetName().ToString(), typeof(IntelCameraWrapper).FullName);
  50. wrapper.init(this);
  51. IsActive = true;
  52. if (DeviceStartedEvent != null) {
  53. DeviceStartedEvent(this, new EventArgs());
  54. DeviceStartedEvent = null; //only notify once...
  55. }
  56. wrapper.run();
  57. if (wrapper.errorstate) {
  58. //we have crashed. Kill the app domain and try again.
  59. Console.WriteLine("Killing AppDomain...");
  60. System.AppDomain.Unload(domain);
  61. Thread.Sleep(5000);
  62. Console.WriteLine("Starting again...");
  63. start();
  64. }
  65. }
  66. public void stop()
  67. {
  68. IsActive = false;
  69. }
  70. internal bool hasNewFrameEvent()
  71. {
  72. return NewFrameEvent != null;
  73. }
  74. internal void killAndRestart()
  75. {
  76. throw new NotImplementedException();
  77. }
  78. internal void newFrame(int currentFrameID, Image<Gray, ushort> dImg)
  79. {
  80. NewFrameEvent(this, new NewFrameEventArgs(currentFrameID, dImg));
  81. }
  82. }
  83. }