123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using System.Timers;
- using System.Threading;
- namespace BBIWARG.Input.InputProviding
- {
- class InputProviderIntel : MarshalByRefObject, IInputProvider
- {
- IntelCameraWrapper wrapper;
- public int CurrentFrameID
- {
- get;
- set;
- }
- public float FieldOfViewHorizontal
- {
- get;
- set;
- }
- public float FieldOfViewVertical
- {
- get;
- set;
- }
- public int ImageWidth
- {
- get { return 640; }
- }
- public int ImageHeight
- {
- get { return 480; }
- }
-
- public bool IsActive
- {
- get;
- set;
- }
- public event DeviceStartedEventHandler DeviceStartedEvent;
- public event NewFrameEventHandler NewFrameEvent;
- public UInt16 lowConfidenceValue;
- private AppDomain domain;
- private System.Threading.Timer watchdogTimer;
- public void initialize()
- {
- CurrentFrameID = 0;
- watchdogTimer = new System.Threading.Timer(Timer_Elapsed, null, 1000, 1000);
- }
- private void Timer_Elapsed(object state)
- {
- checkExitErrorstate();
- if (wrapper != null)
- wrapper.errorstate = true;
- }
- public void start()
- {
- domain = System.AppDomain.CreateDomain(System.Guid.NewGuid().ToString());
- wrapper = (IntelCameraWrapper) domain.CreateInstanceAndUnwrap(typeof(IntelCameraWrapper).Assembly.GetName().ToString(), typeof(IntelCameraWrapper).FullName);
- wrapper.init(this);
- IsActive = true;
- if (DeviceStartedEvent != null) {
- DeviceStartedEvent(this, new EventArgs());
- DeviceStartedEvent = null; //only notify once...
- }
-
- wrapper.run();
- checkExitErrorstate();
- }
- private void checkExitErrorstate()
- {
- if (wrapper.errorstate)
- {
- //we have crashed. Kill the app domain and try again.
- Console.WriteLine("Killing AppDomain...");
- try
- {
- System.AppDomain.Unload(domain);
- Thread.Sleep(5000);
- }
- catch (Exception)
- {
- Console.WriteLine("Could not unload app domain... Still trying to start again...");
- }
-
- Console.WriteLine("Starting again...");
- start();
- }
- }
- public void stop()
- {
- IsActive = false;
- }
- internal bool hasNewFrameEvent()
- {
- return NewFrameEvent != null;
- }
- internal void killAndRestart()
- {
- throw new NotImplementedException();
- }
- internal void newFrame(int currentFrameID, Image<Gray, ushort> dImg)
- {
- NewFrameEvent(this, new NewFrameEventArgs(currentFrameID, dImg));
- }
- }
- }
|