add db WIP 2, 80%

refactor, renames
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-24 06:07:13 +02:00
parent 5fa18aa514
commit 48c9ccbfda
32 changed files with 499 additions and 459 deletions
+15 -3
View File
@@ -1,6 +1,8 @@
using System.IO;
using System.Windows.Media.Imaging;
using Azaion.Common.DTO.Config;
using Azaion.Common.DTO.Queue;
using Azaion.Common.Extensions;
using Azaion.CommonSecurity.DTO;
namespace Azaion.Common.DTO;
@@ -9,26 +11,36 @@ public class Annotation
{
private static string _labelsDir = null!;
private static string _imagesDir = null!;
private static string _thumbDir = null!;
public static void InitializeDirs(DirectoriesConfig config)
{
_labelsDir = config.LabelsDirectory;
_imagesDir = config.ImagesDirectory;
_thumbDir = config.ThumbnailsDirectory;
}
public string Name { get; set; } = null!;
public string ImageExtension { get; set; } = null!;
public DateTime CreatedDate { get; set; }
public List<int> Classes { get; set; } = null!;
public string CreatedEmail { get; set; } = null!;
public RoleEnum CreatedRole { get; set; }
public SourceEnum Source { get; set; }
public AnnotationStatus AnnotationStatus { get; set; }
public string ImagePath => Path.Combine(_imagesDir, $"{Name}.jpg");
public string LabelPath => Path.Combine(_labelsDir, $"{Name}.txt");
public IEnumerable<Detection> Detections { get; set; } = null!;
public double Lat { get; set; }
public double Lon { get; set; }
public List<int> Classes => Detections.Select(x => x.ClassNumber).ToList();
public string ImagePath => Path.Combine(_imagesDir, $"{Name}{ImageExtension}");
public string LabelPath => Path.Combine(_labelsDir, $"{Name}.txt");
public string ThumbPath => Path.Combine(_thumbDir, $"{Name}{Constants.THUMBNAIL_PREFIX}.jpg");
}
public enum AnnotationStatus
{
None = 0,
@@ -0,0 +1,8 @@
using MediatR;
namespace Azaion.Common.DTO;
public class AnnotationCreatedEvent(Annotation annotation) : INotification
{
public Annotation Annotation { get; } = annotation;
}
+38
View File
@@ -0,0 +1,38 @@
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Media.Imaging;
using Azaion.Common.Extensions;
namespace Azaion.Common.DTO;
public class AnnotationImageView(Annotation annotation) : INotifyPropertyChanged
{
public Annotation Annotation { get; set; } = annotation;
private BitmapImage? _thumbnail;
public BitmapImage? Thumbnail
{
get
{
if (_thumbnail == null)
Task.Run(async () => Thumbnail = await Annotation.ThumbPath.OpenImage());
return _thumbnail;
}
private set => _thumbnail = value;
}
public string ImageName => Path.GetFileName(Annotation.ImagePath);
public void Delete()
{
File.Delete(Annotation.ImagePath);
File.Delete(Annotation.LabelPath);
File.Delete(Annotation.ThumbPath);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
+3 -3
View File
@@ -4,12 +4,12 @@ namespace Azaion.Common.DTO.Config;
public class AnnotationConfig
{
public List<AnnotationClass> AnnotationClasses { get; set; } = null!;
public List<DetectionClass> AnnotationClasses { get; set; } = null!;
[JsonIgnore]
private Dictionary<int, AnnotationClass>? _annotationClassesDict;
private Dictionary<int, DetectionClass>? _detectionClassesDict;
[JsonIgnore]
public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
public Dictionary<int, DetectionClass> DetectionClassesDict => _detectionClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
public int? LastSelectedExplorerClass { get; set; }
@@ -4,7 +4,7 @@ using Newtonsoft.Json;
namespace Azaion.Common.DTO;
public class AnnotationClass
public class DetectionClass
{
public int Id { get; set; }
-8
View File
@@ -1,8 +0,0 @@
using MediatR;
namespace Azaion.Common.DTO;
public class ImageCreatedEvent(string imagePath) : INotification
{
public string ImagePath { get; } = imagePath;
}
+16 -6
View File
@@ -41,12 +41,14 @@ public class CanvasLabel : Label
Probability = probability;
}
public CanvasLabel(YoloLabel label, Size canvasSize, Size videoSize, double? probability = null)
public CanvasLabel(YoloLabel label, Size canvasSize, Size? videoSize = null, double? probability = null)
{
var cw = canvasSize.Width;
var ch = canvasSize.Height;
var canvasAr = cw / ch;
var videoAr = videoSize.Width / videoSize.Height;
var videoAr = videoSize.HasValue
? videoSize.Value.Width / videoSize.Value.Height
: canvasAr;
ClassNumber = label.ClassNumber;
@@ -102,12 +104,14 @@ public class YoloLabel : Label
public RectangleF ToRectangle() =>
new((float)(CenterX - Width / 2.0), (float)(CenterY - Height / 2.0), (float)Width, (float)Height);
public YoloLabel(CanvasLabel canvasLabel, Size canvasSize, Size videoSize)
public YoloLabel(CanvasLabel canvasLabel, Size canvasSize, Size? videoSize = null)
{
var cw = canvasSize.Width;
var ch = canvasSize.Height;
var canvasAr = cw / ch;
var videoAr = videoSize.Width / videoSize.Height;
var videoAr = videoSize.HasValue
? videoSize.Value.Width / videoSize.Value.Height
: canvasAr;
ClassNumber = canvasLabel.ClassNumber;
@@ -182,8 +186,15 @@ public class YoloLabel : Label
public class Detection : YoloLabel
{
public Detection(YoloLabel label, double? probability = null)
public string AnnotationName { get; set; }
public double? Probability { get; set; }
//For db
public Detection(){}
public Detection(string annotationName, YoloLabel label, double? probability = null)
{
AnnotationName = annotationName;
ClassNumber = label.ClassNumber;
CenterX = label.CenterX;
CenterY = label.CenterY;
@@ -191,5 +202,4 @@ public class Detection : YoloLabel
Width = label.Width;
Probability = probability;
}
public double? Probability { get; set; }
}
@@ -6,14 +6,15 @@ using MessagePack;
[MessagePackObject]
public class AnnotationCreatedMessage
{
[Key(0)] public DateTime CreatedDate { get; set; }
[Key(1)] public string Name { get; set; } = null!;
[Key(2)] public string Label { get; set; } = null!;
[Key(3)] public byte[] Image { get; set; } = null!;
[Key(4)] public RoleEnum CreatedRole { get; set; }
[Key(5)] public string CreatedEmail { get; set; } = null!;
[Key(6)] public SourceEnum Source { get; set; }
[Key(7)] public AnnotationStatus Status { get; set; }
[Key(0)] public DateTime CreatedDate { get; set; }
[Key(1)] public string Name { get; set; } = null!;
[Key(2)] public string ImageExtension { get; set; } = null!;
[Key(3)] public string Detections { get; set; } = null!;
[Key(4)] public byte[] Image { get; set; } = null!;
[Key(5)] public RoleEnum CreatedRole { get; set; }
[Key(6)] public string CreatedEmail { get; set; } = null!;
[Key(7)] public SourceEnum Source { get; set; }
[Key(8)] public AnnotationStatus Status { get; set; }
}
[MessagePackObject]