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
+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(',', '.');
}