mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:46:30 +00:00
rework to Azaion.Suite, show tabs with annotator and dataset explorer
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Services;
|
||||
using Compunet.YoloV8;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SixLabors.ImageSharp;
|
||||
@@ -12,18 +14,27 @@ namespace Azaion.Annotator;
|
||||
|
||||
public interface IAIDetector
|
||||
{
|
||||
List<Detection> Detect(Stream stream);
|
||||
Task<List<Detection>> Detect(Stream imageStream, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public class YOLODetector(AIRecognitionConfig recognitionConfig) : IAIDetector, IDisposable
|
||||
public class YOLODetector(IOptions<AIRecognitionConfig> recognitionConfig, IResourceLoader resourceLoader) : IAIDetector, IDisposable
|
||||
{
|
||||
private readonly YoloPredictor _predictor = new(recognitionConfig.AIModelPath);
|
||||
private readonly AIRecognitionConfig _recognitionConfig = recognitionConfig.Value;
|
||||
private YoloPredictor? _predictor;
|
||||
private const string YOLO_MODEL = "azaion.onnx";
|
||||
|
||||
public List<Detection> Detect(Stream stream)
|
||||
|
||||
public async Task<List<Detection>> Detect(Stream imageStream, CancellationToken cancellationToken)
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var image = Image.Load<Rgb24>(stream);
|
||||
var result = _predictor.Detect(image);
|
||||
if (_predictor == null)
|
||||
{
|
||||
await using var stream = await resourceLoader.Load(YOLO_MODEL, cancellationToken);
|
||||
_predictor = new YoloPredictor(stream.ToArray());
|
||||
}
|
||||
|
||||
imageStream.Seek(0, SeekOrigin.Begin);
|
||||
var image = Image.Load<Rgb24>(imageStream);
|
||||
var result = await _predictor.DetectAsync(image);
|
||||
|
||||
var imageSize = new System.Windows.Size(image.Width, image.Height);
|
||||
|
||||
@@ -38,7 +49,7 @@ public class YOLODetector(AIRecognitionConfig recognitionConfig) : IAIDetector,
|
||||
|
||||
private List<Detection> FilterOverlapping(List<Detection> detections)
|
||||
{
|
||||
var k = recognitionConfig.TrackingIntersectionThreshold;
|
||||
var k = _recognitionConfig.TrackingIntersectionThreshold;
|
||||
var filteredDetections = new List<Detection>();
|
||||
for (var i = 0; i < detections.Count; i++)
|
||||
{
|
||||
@@ -73,5 +84,5 @@ public class YOLODetector(AIRecognitionConfig recognitionConfig) : IAIDetector,
|
||||
return filteredDetections;
|
||||
}
|
||||
|
||||
public void Dispose() => _predictor.Dispose();
|
||||
public void Dispose() => _predictor?.Dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user