io commander
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using OpenCvSharp;
|
||||
using System.Drawing;
|
||||
using System.Threading.Channels;
|
||||
using Ninject;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
@@ -23,7 +24,31 @@ namespace Hawkeye.VisionBuilder.UI.Sources.Emulation
|
||||
return _name;
|
||||
}
|
||||
|
||||
private Channel<Mat> _channel = Channel.CreateBounded<Mat>(new BoundedChannelOptions(1)
|
||||
{
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
SingleReader = true,
|
||||
SingleWriter = true,
|
||||
AllowSynchronousContinuations = true
|
||||
});
|
||||
public async Task<Mat> GetImage(CancellationToken token)
|
||||
{
|
||||
//clear the channel if it is full
|
||||
if (_channel.Reader.Count > 0)
|
||||
{
|
||||
while (await _channel.Reader.WaitToReadAsync(token))
|
||||
{
|
||||
if (_channel.Reader.TryRead(out _)) continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//get the next image
|
||||
await Task.Run(new Action(() => _ = GetImageInternal(CancellationToken.None)), token);
|
||||
|
||||
return await _channel.Reader.ReadAsync(token);
|
||||
}
|
||||
|
||||
public async Task<Mat> GetImageInternal(CancellationToken token)
|
||||
{
|
||||
if (_selectedFiles.Length == 0) return null;
|
||||
var id = (_index) % _selectedFiles.Length;
|
||||
@@ -50,8 +75,9 @@ namespace Hawkeye.VisionBuilder.UI.Sources.Emulation
|
||||
|
||||
|
||||
Console.WriteLine($"Getting image {path}");
|
||||
|
||||
return Cv2.ImRead(path);
|
||||
var res= Cv2.ImRead(path);
|
||||
await _channel.Writer.WriteAsync(res, token);
|
||||
return res;
|
||||
}
|
||||
public void SetFolder(string imagesFolder)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user