rework to Azaion.Suite

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-21 13:41:32 +02:00
parent 2cf69f4e4e
commit 5a592e9dbf
76 changed files with 1739 additions and 882 deletions
+19 -18
View File
@@ -1,11 +1,12 @@
using System.IO;
using Azaion.Annotator.DTO;
using Azaion.Annotator.Extensions;
using Azaion.Common.DTO;
using Compunet.YoloV8;
using Compunet.YoloV8.Data;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Detection = Azaion.Annotator.DTO.Detection;
using Detection = Azaion.Common.DTO.Detection;
namespace Azaion.Annotator;
@@ -14,9 +15,9 @@ public interface IAIDetector
List<Detection> Detect(Stream stream);
}
public class YOLODetector(Config config) : IAIDetector, IDisposable
public class YOLODetector(AIRecognitionConfig recognitionConfig) : IAIDetector, IDisposable
{
private readonly YoloPredictor _predictor = new(config.AIRecognitionConfig.AIModelPath);
private readonly YoloPredictor _predictor = new(recognitionConfig.AIModelPath);
public List<Detection> Detect(Stream stream)
{
@@ -37,7 +38,7 @@ public class YOLODetector(Config config) : IAIDetector, IDisposable
private List<Detection> FilterOverlapping(List<Detection> detections)
{
var k = config.AIRecognitionConfig.TrackingIntersectionThreshold;
var k = recognitionConfig.TrackingIntersectionThreshold;
var filteredDetections = new List<Detection>();
for (var i = 0; i < detections.Count; i++)
{
@@ -48,21 +49,21 @@ public class YOLODetector(Config config) : IAIDetector, IDisposable
intersect.Intersect(detections[j].ToRectangle());
var maxArea = Math.Max(detections[i].ToRectangle().Area(), detections[j].ToRectangle().Area());
if (intersect.Area() > k * maxArea)
if (!(intersect.Area() > k * maxArea))
continue;
if (detections[i].Probability > detections[j].Probability)
{
if (detections[i].Probability > detections[j].Probability)
{
filteredDetections.Add(detections[i]);
detections.RemoveAt(j);
}
else
{
filteredDetections.Add(detections[j]);
detections.RemoveAt(i);
}
detectionSelected = true;
break;
filteredDetections.Add(detections[i]);
detections.RemoveAt(j);
}
else
{
filteredDetections.Add(detections[j]);
detections.RemoveAt(i);
}
detectionSelected = true;
break;
}
if (!detectionSelected)