check point
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using OpenCvSharp;
|
||||
using System.Drawing;
|
||||
using Ninject;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.UI.Sources.Emulation
|
||||
{
|
||||
public class EmulationCameraImageSource:IImageSource, IInitializable
|
||||
{
|
||||
private readonly EmulationSettings _settings;
|
||||
private readonly string _name;
|
||||
private string _currentFolder;
|
||||
private string[] _selectedFiles;
|
||||
|
||||
public EmulationCameraImageSource(EmulationSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public async Task<Mat> GetImage(CancellationToken token)
|
||||
{
|
||||
if (_selectedFiles.Length == 0) return null;
|
||||
var id = (_index) % _selectedFiles.Length;
|
||||
if (id == 0)
|
||||
{
|
||||
if (_index > 0)
|
||||
OnLoopOver();
|
||||
if (_settings.SingleRun && _index > 0)
|
||||
{
|
||||
// infinite sleep
|
||||
await Task.Delay(Timeout.Infinite, token);
|
||||
}
|
||||
Console.WriteLine("starting new emulation cycle");
|
||||
await Task.Delay(_settings.CycleDelay, token);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(_settings.PerImageDelay, token);
|
||||
}
|
||||
|
||||
var path = _selectedFiles[id];
|
||||
_index++;
|
||||
|
||||
|
||||
|
||||
Console.WriteLine($"Getting image {path}");
|
||||
|
||||
return Cv2.ImRead(path);
|
||||
}
|
||||
public void SetFolder(string imagesFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentFolder = imagesFolder;
|
||||
var path = Path.Combine(@"..\Data\Emulation", imagesFolder);
|
||||
_selectedFiles = Directory.GetFiles(path, "*.bmp")
|
||||
.Concat(Directory.GetFiles(path, "*.png"))
|
||||
.Concat(Directory.GetFiles(path, "*.jpg"))
|
||||
.Where(x => !Path.GetFileNameWithoutExtension(x).Contains("_analysis"))
|
||||
.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFolderAbsolute(string imagesFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentFolder = imagesFolder;
|
||||
var path = imagesFolder;
|
||||
_selectedFiles = Directory.GetFiles(path, "*.bmp")
|
||||
.Concat(Directory.GetFiles(path, "*.png"))
|
||||
.Concat(Directory.GetFiles(path, "*.jpg"))
|
||||
.Where(x => !Path.GetFileNameWithoutExtension(x).Contains("_analysis"))
|
||||
.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public event Action OnLoopOver = delegate { };
|
||||
private int _index = 0;
|
||||
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if(string.IsNullOrEmpty(_settings.EmulationPath)) return;
|
||||
SetFolderAbsolute(_settings.EmulationPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Inspectron.Settings;
|
||||
using VisionBuilder.UI.Common;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.UI.Sources.Emulation;
|
||||
|
||||
public class EmulationSettings : ISettings
|
||||
{
|
||||
public string CameraName { get; }
|
||||
|
||||
public EmulationSettings(string cameraName)
|
||||
{
|
||||
CameraName = cameraName;
|
||||
}
|
||||
|
||||
public int CycleDelay { get; set; } = 1;
|
||||
public int PerImageDelay { get; set; } = 5000;
|
||||
public bool SingleRun { get; set; } = false;
|
||||
public string EmulationPath { get; set; }
|
||||
|
||||
public void RegisterSettings(InspectronSettings settings)
|
||||
{
|
||||
settings.RegisterSimple(this, () => CycleDelay, CameraName+"/Emulation", nameof(CycleDelay));
|
||||
settings.RegisterSimple(this, () => PerImageDelay, CameraName + "/Emulation", nameof(PerImageDelay));
|
||||
settings.RegisterSimple(this, () => SingleRun, CameraName + "/Emulation", nameof(SingleRun));
|
||||
settings.RegisterSimple(this, () => EmulationPath, CameraName + "/Emulation", nameof(EmulationPath));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VisionBuilder.UI.Common\VisionBuilder.UI.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user