add generating result image to Results directory

This commit is contained in:
Alex Bezdieniezhnykh
2025-04-03 11:06:00 +03:00
parent 83ae6a0ae9
commit c9800107a6
15 changed files with 86 additions and 61 deletions
+19
View File
@@ -265,6 +265,24 @@ public class GalleryService(
logger.LogError(e, e.Message);
}
}
public async Task CreateAnnotatedImage(Annotation annotation, CancellationToken token)
{
var originalImage = Image.FromStream(new MemoryStream(await File.ReadAllBytesAsync(annotation.ImagePath, token)));
using var g = Graphics.FromImage(originalImage);
foreach (var detection in annotation.Detections)
{
var detClass = _annotationConfig.DetectionClassesDict[detection.ClassNumber];
var color = detClass.Color;
var brush = new SolidBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
var det = new CanvasLabel(detection, new Size(originalImage.Width, originalImage.Height));
g.DrawRectangle(new Pen(brush, width: 3), (float)det.X, (float)det.Y, (float)det.Width, (float)det.Height);
var label = detection.Confidence >= 0.995 ? detClass.UIName : $"{detClass.UIName}: {detection.Confidence * 100:F0}%";
g.DrawString(label, new Font(FontFamily.GenericSerif, 14), brush, new PointF((float)(det.X + det.Width / 2.0), (float)det.Y));
}
originalImage.Save(Path.Combine(_dirConfig.ResultsDirectory, $"{annotation.Name}{Constants.RESULT_PREFIX}.jpg"), ImageFormat.Jpeg);
}
}
public interface IGalleryService
@@ -275,4 +293,5 @@ public interface IGalleryService
Task RefreshThumbnails();
Task ClearThumbnails(CancellationToken cancellationToken = default);
Task CreateAnnotatedImage(Annotation annotation, CancellationToken token);
}