long candy ready to test
This commit is contained in:
13
VisionBuilder.UI.Recipes.HawkeyeRecipe/EmptyImageSource.cs
Normal file
13
VisionBuilder.UI.Recipes.HawkeyeRecipe/EmptyImageSource.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using OpenCvSharp;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
|
||||
namespace VisionBuilder.UI.Recipes.HawkeyeRecipe;
|
||||
|
||||
public class EmptyImageSource: IImageSource
|
||||
{
|
||||
|
||||
public Task<Mat> GetImage(CancellationToken token)
|
||||
{
|
||||
return Task.FromResult(new Mat(480, 640, MatType.CV_8UC3, Scalar.Black));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Diagnostics;
|
||||
using System.CodeDom;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Hawkeye.VisionBuilder.Workflow;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations;
|
||||
using Serilog;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
using VisionBuilder.UI.Common.ViewModel.Classes;
|
||||
@@ -86,6 +89,25 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe
|
||||
_startTime = DateTime.Now;
|
||||
IsRunning = true;
|
||||
_cts = new CancellationTokenSource();
|
||||
|
||||
|
||||
Log.Information($"Warming up");
|
||||
try
|
||||
{
|
||||
var swWarmup = Stopwatch.StartNew();
|
||||
// warmup run
|
||||
_workflow.ImageSource = new EmptyImageSource();
|
||||
_workflow.Context = new Context();
|
||||
_workflow.Context.CancellationToken = CancellationToken.None;
|
||||
_workflow.Execute(); // Warmup run
|
||||
swWarmup.Stop();
|
||||
Log.Information($"Warmup run took {swWarmup.ElapsedMilliseconds} ms");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error during warmup run");
|
||||
}
|
||||
|
||||
_loopTask = Task.Run(() => Loop(_cts.Token), _cts.Token);
|
||||
|
||||
SessionStarted?.Invoke(new SessionStartedEvent
|
||||
@@ -174,11 +196,19 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe
|
||||
var annotated = _workflow.Context.ActiveImage.ImageData.Clone();
|
||||
var canvas = new OpenCVCanvas(annotated);
|
||||
_workflow.Context.GraphicsElements.ForEach(x => x.Draw(canvas));
|
||||
|
||||
TimeSpan cameraTime = TimeSpan.FromMilliseconds(0);
|
||||
var cameraOperation = _workflow.Operations.FirstOrDefault(x => x is GetImageOperation);
|
||||
if (cameraOperation != null)
|
||||
{
|
||||
cameraTime=cameraOperation.ExecutionTime;
|
||||
}
|
||||
|
||||
var processingResult = new ImageProcessedEvent()
|
||||
{
|
||||
SessionStart = _startTime,
|
||||
RecipeName = _currentRecipe.RecipeName,
|
||||
AnalysisTime = sw.Elapsed,
|
||||
AnalysisTime = sw.Elapsed- cameraTime,
|
||||
ErrorNames = errorNames.ToList(),
|
||||
HasError = errorNames.Length > 0,
|
||||
ImageSource = _recognitionConfiguration.CameraName,
|
||||
@@ -186,7 +216,10 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe
|
||||
ImageAnalysis = annotated
|
||||
};
|
||||
|
||||
var swProcessed = Stopwatch.StartNew();
|
||||
ImageProcessed(processingResult);
|
||||
swProcessed.Stop();
|
||||
Log.Information($"ImageProcessed event handled in {swProcessed.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user