long candy ready to test
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Inspectron.Fastbuffer.Filesystems;
|
||||
using Lindt.Colorballs.Duo.Utils;
|
||||
using OpenCvSharp;
|
||||
using Serilog;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
@@ -12,26 +13,58 @@ public class VisionBuilderRingbuffer:IVisionBuilderModule
|
||||
{
|
||||
private readonly VisionBuilderRingbufferSettings _settings;
|
||||
private readonly IRecognitionControl _recognitionControl;
|
||||
private readonly ILoadingService _loadingService;
|
||||
|
||||
public VisionBuilderRingbuffer(VisionBuilderRingbufferSettings settings, IRecognitionControl recognitionControl)
|
||||
public VisionBuilderRingbuffer(VisionBuilderRingbufferSettings settings, IRecognitionControl recognitionControl, ILoadingService loadingService)
|
||||
{
|
||||
_settings = settings;
|
||||
_recognitionControl = recognitionControl;
|
||||
|
||||
_loadingService = loadingService;
|
||||
}
|
||||
public void InitializeModule()
|
||||
{
|
||||
_recognitionControl.SessionStarted += _recognitionControl_SessionStarted;
|
||||
_recognitionControl.SessionEnded += _recognitionControl_SessionEnded;
|
||||
_recognitionControl.ImageProcessed += _recognitionControl_ImageProcessed;
|
||||
}
|
||||
|
||||
private void _recognitionControl_SessionEnded(SessionEndedEvent obj)
|
||||
{
|
||||
_loadingService.StartLoading("Processing ringbuffer");
|
||||
Log.Information("Processing ringbuffer");
|
||||
try
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.Information("Finished processing ringbuffer");
|
||||
_loadingService.StopLoading("Processing ringbuffer");
|
||||
}
|
||||
}
|
||||
|
||||
private void _recognitionControl_ImageProcessed(VisionBuilder.UI.Common.Commands.ImageProcessedEvent obj)
|
||||
{
|
||||
if (obj.HasError)
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
WriteBadResult(obj);
|
||||
return;
|
||||
if (obj.HasError)
|
||||
{
|
||||
WriteBadResult(obj);
|
||||
return;
|
||||
}
|
||||
WriteGoodResult(obj);
|
||||
}
|
||||
WriteGoodResult(obj);
|
||||
finally
|
||||
{
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Ringbuffer: wrote image in {sw.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void _recognitionControl_SessionStarted(VisionBuilder.UI.Common.Commands.SessionStartedEvent obj)
|
||||
@@ -43,11 +76,20 @@ public class VisionBuilderRingbuffer:IVisionBuilderModule
|
||||
private string _path;
|
||||
private DateTime _startTime;
|
||||
private string _product;
|
||||
|
||||
|
||||
private void CleanUp()
|
||||
{
|
||||
_goodRingbufferIsolated?.Dispose();
|
||||
foreach (var ringbuffer in _badRingbuffers)
|
||||
{
|
||||
ringbuffer.Value.Dispose();
|
||||
}
|
||||
_badRingbuffers.Clear();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +100,7 @@ public class VisionBuilderRingbuffer:IVisionBuilderModule
|
||||
try
|
||||
{
|
||||
var image = result.ImageOriginal;
|
||||
// save to memory stream
|
||||
_goodRingbufferIsolated.Write(image.ToBytes(), filename);
|
||||
_goodRingbufferIsolated.Write(image, filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -87,9 +128,7 @@ public class VisionBuilderRingbuffer:IVisionBuilderModule
|
||||
var ringbuffer = GetBadRingbuffer(defectName);
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
ringbuffer.Write(image.ToBytes(), filename);
|
||||
ringbuffer.Write(image, filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -116,15 +155,10 @@ public class VisionBuilderRingbuffer:IVisionBuilderModule
|
||||
_startTime = DateTime.Now;
|
||||
_product = product;
|
||||
_path = PathSettingsUtils.ConvertVariables(Path.Combine(_settings.Root,_settings.GoodImagesPathTemplate), _startTime, _startTime, _product,cameraName:_settings.CameraName);
|
||||
_goodRingbufferIsolated?.Dispose();
|
||||
|
||||
_goodRingbufferIsolated = new IsolatedRingbuffer(_path, _settings.MaxGood, new AsyncFilesystem());
|
||||
|
||||
foreach (var ringbuffer in _badRingbuffers)
|
||||
{
|
||||
ringbuffer.Value.Dispose();
|
||||
}
|
||||
|
||||
_badRingbuffers.Clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ Specifies directory, in which MaxBad and MaxGood are applied.
|
||||
|
||||
[SettingDescription("Specifies directory, relative to the Root")]
|
||||
[SettingPreview(typeof(VisionBuilderRingbufferSettings), nameof(ImagesPathTemplatePreview))]
|
||||
public string GoodImagesPathTemplate { get; set; } = @"\$RECIPE_NAME";
|
||||
public string GoodImagesPathTemplate { get; set; } = @"$RECIPE_NAME";
|
||||
|
||||
[SettingDescription("Specifies directory, relative to the Root")]
|
||||
[SettingPreview(typeof(VisionBuilderRingbufferSettings),nameof(ImagesPathTemplatePreview))]
|
||||
public string BadImagesPathTemplate { get; set; } =
|
||||
@"\$RECIPE_NAME\$DEFECT_NAME";
|
||||
@"$RECIPE_NAME\$DEFECT_NAME";
|
||||
|
||||
|
||||
[SettingPreview(typeof(VisionBuilderRingbufferSettings), nameof(ImagesPathTemplatePreview))]
|
||||
|
||||
Reference in New Issue
Block a user