add autodetection

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-02 13:09:00 +02:00
parent b5b77d9492
commit 418a2116b7
19 changed files with 545 additions and 268 deletions
+36
View File
@@ -0,0 +1,36 @@
using System.Drawing.Imaging;
using System.IO;
using Azaion.Annotator.DTO;
using Compunet.YoloV8;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
namespace Azaion.Annotator;
public interface IAIDetector
{
List<(YoloLabel Label, float Probability)> Detect(Stream stream);
}
public class YOLODetector(Config config) : IAIDetector, IDisposable
{
private readonly YoloPredictor _predictor = new(config.AIRecognitionConfig.AIModelPath);
public List<(YoloLabel Label, float Probability)> Detect(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
var image = Image.Load<Rgb24>(stream);
var result = _predictor.Detect(image);
var imageSize = new System.Windows.Size(image.Width, image.Height);
return result.Select(d =>
{
var label = new YoloLabel(new CanvasLabel(d.Name.Id, d.Bounds.X, d.Bounds.Y, d.Bounds.Width, d.Bounds.Height), imageSize, imageSize);
return (label, d.Confidence * 100);
}).ToList();
}
public void Dispose() => _predictor.Dispose();
}