add autodetection

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-02 13:09:00 +02:00
parent b5b77d9492
commit 418a2116b7
19 changed files with 545 additions and 268 deletions
+9 -6
View File
@@ -9,11 +9,11 @@ public abstract class Label
{
[JsonProperty(PropertyName = "cl")] public int ClassNumber { get; set; }
public Label()
protected Label()
{
}
public Label(int classNumber)
protected Label(int classNumber)
{
ClassNumber = classNumber;
}
@@ -25,20 +25,22 @@ public class CanvasLabel : Label
public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public double? Probability { get; }
public CanvasLabel()
{
}
public CanvasLabel(int classNumber, double x, double y, double width, double height) : base(classNumber)
public CanvasLabel(int classNumber, double x, double y, double width, double height, double? probability = null) : base(classNumber)
{
X = x;
Y = y;
Width = width;
Height = height;
Probability = probability;
}
public CanvasLabel(YoloLabel label, Size canvasSize, Size videoSize)
public CanvasLabel(YoloLabel label, Size canvasSize, Size videoSize, double? probability = null)
{
var cw = canvasSize.Width;
var ch = canvasSize.Height;
@@ -70,6 +72,7 @@ public class CanvasLabel : Label
Width = label.Width * realWidth;
Height = label.Height * ch;
}
Probability = probability;
}
}
@@ -158,10 +161,10 @@ public class YoloLabel : Label
.ToList()!;
}
public static async Task WriteToFile(IEnumerable<YoloLabel> labels, string filename)
public static async Task WriteToFile(IEnumerable<YoloLabel> labels, string filename, CancellationToken cancellationToken = default)
{
var labelsStr = string.Join(Environment.NewLine, labels.Select(x => x.ToString()));
await File.WriteAllTextAsync(filename, labelsStr);
await File.WriteAllTextAsync(filename, labelsStr, cancellationToken);
}
public override string ToString() => $"{ClassNumber} {CenterX:F5} {CenterY:F5} {Width:F5} {Height:F5}".Replace(',', '.');