add editor, fix some bugs

WIP
This commit is contained in:
Alex Bezdieniezhnykh
2024-09-10 17:10:54 +03:00
parent b4bedb7520
commit 52371ace3a
16 changed files with 498 additions and 148 deletions
+23 -6
View File
@@ -1,6 +1,5 @@
using System.IO;
using System.Text;
using System.Windows.Media;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Size = System.Windows.Size;
@@ -11,21 +10,22 @@ namespace Azaion.Annotator.DTO;
public class Config
{
public const string ThumbnailPrefix = "_thumb";
public const string ThumbnailsCacheFile = "thumbnails.cache";
public string VideosDirectory { get; set; }
public string LabelsDirectory { get; set; }
public string ImagesDirectory { get; set; }
public string ResultsDirectory { get; set; }
public string ThumbnailsDirectory { get; set; }
public string UnknownImages { get; set; }
public List<AnnotationClass> AnnotationClasses { get; set; } = [];
private Dictionary<int, AnnotationClass>? _annotationClassesDict;
public Dictionary<int, AnnotationClass> AnnotationClassesDict => _annotationClassesDict ??= AnnotationClasses.ToDictionary(x => x.Id);
public Size WindowSize { get; set; }
public Point WindowLocation { get; set; }
public bool FullScreen { get; set; }
public WindowConfig MainWindowConfig { get; set; }
public WindowConfig DatasetExplorerConfig { get; set; }
public double LeftPanelWidth { get; set; }
public double RightPanelWidth { get; set; }
@@ -38,6 +38,13 @@ public class Config
public ThumbnailConfig ThumbnailConfig { get; set; }
}
public class WindowConfig
{
public Size WindowSize { get; set; }
public Point WindowLocation { get; set; }
public bool FullScreen { get; set; }
}
public class ThumbnailConfig
{
public Size Size { get; set; }
@@ -60,6 +67,7 @@ public class FileConfigRepository(ILogger<FileConfigRepository> logger) : IConfi
private const string DEFAULT_IMAGES_DIR = "images";
private const string DEFAULT_RESULTS_DIR = "results";
private const string DEFAULT_THUMBNAILS_DIR = "thumbnails";
private const string DEFAULT_UNKNOWN_IMG_DIR = "unknown";
private static readonly Size DefaultWindowSize = new(1280, 720);
private static readonly Point DefaultWindowLocation = new(100, 100);
@@ -82,9 +90,18 @@ public class FileConfigRepository(ILogger<FileConfigRepository> logger) : IConfi
ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR),
ResultsDirectory = Path.Combine(exePath, DEFAULT_RESULTS_DIR),
ThumbnailsDirectory = Path.Combine(exePath, DEFAULT_THUMBNAILS_DIR),
UnknownImages = Path.Combine(exePath, DEFAULT_UNKNOWN_IMG_DIR),
WindowLocation = DefaultWindowLocation,
WindowSize = DefaultWindowSize,
MainWindowConfig = new WindowConfig
{
WindowSize = DefaultWindowSize,
WindowLocation = DefaultWindowLocation
},
DatasetExplorerConfig = new WindowConfig
{
WindowSize = DefaultWindowSize,
WindowLocation = DefaultWindowLocation
},
ShowHelpOnStart = true,
VideoFormats = DefaultVideoFormats,
-2
View File
@@ -6,8 +6,6 @@ namespace Azaion.Annotator.DTO;
public class FormState
{
public SelectionState SelectionState { get; set; } = SelectionState.None;
public MediaFileInfo? CurrentMedia { get; set; }
public string VideoName => string.IsNullOrEmpty(CurrentMedia?.Name)
? ""
+37 -25
View File
@@ -7,11 +7,16 @@ namespace Azaion.Annotator.DTO;
public abstract class Label
{
[JsonProperty(PropertyName = "cl")]
public int ClassNumber { get; set; }
public Label(){}
public Label(int classNumber) { ClassNumber = classNumber; }
[JsonProperty(PropertyName = "cl")] public int ClassNumber { get; set; }
public Label()
{
}
public Label(int classNumber)
{
ClassNumber = classNumber;
}
}
public class CanvasLabel : Label
@@ -20,8 +25,11 @@ public class CanvasLabel : Label
public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public CanvasLabel() { }
public CanvasLabel()
{
}
public CanvasLabel(int classNumber, double x, double y, double width, double height) : base(classNumber)
{
X = x;
@@ -36,17 +44,17 @@ public class CanvasLabel : Label
var ch = canvasSize.Height;
var canvasAr = cw / ch;
var videoAr = videoSize.Width / videoSize.Height;
ClassNumber = label.ClassNumber;
var left = label.CenterX - label.Width / 2;
var top = label.CenterY - label.Height / 2;
if (videoAr > canvasAr) //100% width
{
var realHeight = cw / videoAr; //real video height in pixels on canvas
var blackStripHeight = (ch - realHeight) / 2.0; //height of black strips at the top and bottom
X = left * cw;
Y = top * realHeight + blackStripHeight;
Width = label.Width * cw;
@@ -67,19 +75,18 @@ public class CanvasLabel : Label
public class YoloLabel : Label
{
[JsonProperty(PropertyName = "x")]
public double CenterX { get; set; }
[JsonProperty(PropertyName = "x")] public double CenterX { get; set; }
[JsonProperty(PropertyName = "y")]
public double CenterY { get; set; }
[JsonProperty(PropertyName = "y")] public double CenterY { get; set; }
[JsonProperty(PropertyName = "w")]
public double Width { get; set; }
[JsonProperty(PropertyName = "w")] public double Width { get; set; }
[JsonProperty(PropertyName = "h")] public double Height { get; set; }
public YoloLabel()
{
}
[JsonProperty(PropertyName = "h")]
public double Height { get; set; }
public YoloLabel() { }
public YoloLabel(int classNumber, double centerX, double centerY, double width, double height) : base(classNumber)
{
CenterX = centerX;
@@ -96,7 +103,7 @@ public class YoloLabel : Label
var videoAr = videoSize.Width / videoSize.Height;
ClassNumber = canvasLabel.ClassNumber;
double left, top;
if (videoAr > canvasAr) //100% width
{
@@ -125,8 +132,8 @@ public class YoloLabel : Label
{
if (string.IsNullOrEmpty(s))
return null;
var strings = s.Replace(',','.').Split(' ');
var strings = s.Replace(',', '.').Split(' ');
if (strings.Length != 5)
return null;
@@ -158,6 +165,11 @@ public class YoloLabel : Label
.ToList()!;
}
public static async Task WriteToFile(IEnumerable<YoloLabel> labels, string filename)
{
var labelsStr = string.Join(Environment.NewLine, labels.Select(x => x.ToString()));
await File.WriteAllTextAsync(filename, labelsStr);
}
public override string ToString() => $"{ClassNumber} {CenterX:F5} {CenterY:F5} {Width:F5} {Height:F5}".Replace(',', '.');
}