|
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|
|
using Emgu.CV;
|
|
|
using Emgu.CV.Structure;
|
|
|
using System.Drawing;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace BBIWARG.Input.InputProviding
|
|
|
{
|
|
@@ -104,24 +105,39 @@ namespace BBIWARG.Input.InputProviding
|
|
|
Console.WriteLine("Trying to reinitialize the camera...");
|
|
|
Task<bool> initCameraTask = Task.Run(() => restartCamera());
|
|
|
crashed = !initCameraTask.Wait(TimeSpan.FromSeconds(5)) || !initCameraTask.Result;
|
|
|
+
|
|
|
+ Thread.Yield();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ crashed = !tryAcquireAndHandleFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool tryAcquireAndHandleFrame()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //try to acquire new frame...
|
|
|
+ Task<bool> acquireFrameTask = Task.Run(() => acquireNewFrame());
|
|
|
+ //wait a second...
|
|
|
+ if (acquireFrameTask.Wait(TimeSpan.FromSeconds(4)) && acquireFrameTask.Result)
|
|
|
+ {
|
|
|
+ //that worked, we should have a new frame by now...
|
|
|
+ handleNewFrame();
|
|
|
+ senseManager.ReleaseFrame();
|
|
|
+ return true;
|
|
|
}
|
|
|
else {
|
|
|
- //try to acquire new frame...
|
|
|
- Task acquireFrameTask = Task.Run(() => acquireNewFrame());
|
|
|
- //wait a second...
|
|
|
- if (acquireFrameTask.Wait(TimeSpan.FromSeconds(1)))
|
|
|
- {
|
|
|
- //that worked, we should have a new frame by now...
|
|
|
- handleNewFrame();
|
|
|
- senseManager.ReleaseFrame();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //cam crashed. try to dispose and start again.
|
|
|
- crashed = true;
|
|
|
- }
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Exception while acquiring frame: " + e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private bool restartCamera()
|