mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16:30 +00:00
fix bug with annotation result gradient stops
add tensorrt engine
This commit is contained in:
@@ -90,5 +90,5 @@ public class Constants
|
||||
|
||||
#endregion
|
||||
|
||||
public const string CSV_PATH = "D:\\matches.csv";
|
||||
public const string CSV_PATH = "matches.csv";
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class CanvasEditor : Canvas
|
||||
_verticalLine.Fill = value.ColorBrush;
|
||||
_horizontalLine.Stroke = value.ColorBrush;
|
||||
_horizontalLine.Fill = value.ColorBrush;
|
||||
_classNameHint.Text = value.Name;
|
||||
_classNameHint.Text = value.ShortName;
|
||||
|
||||
_newAnnotationRect.Stroke = value.ColorBrush;
|
||||
_newAnnotationRect.Fill = value.ColorBrush;
|
||||
@@ -84,7 +84,7 @@ public class CanvasEditor : Canvas
|
||||
};
|
||||
_classNameHint = new TextBlock
|
||||
{
|
||||
Text = CurrentAnnClass?.Name ?? "asd",
|
||||
Text = CurrentAnnClass?.ShortName ?? "",
|
||||
Foreground = new SolidColorBrush(Colors.Black),
|
||||
Cursor = Cursors.Arrow,
|
||||
FontSize = 16,
|
||||
@@ -313,14 +313,14 @@ public class CanvasEditor : Canvas
|
||||
foreach (var detection in detections)
|
||||
{
|
||||
var annClass = DetectionClass.FromYoloId(detection.ClassNumber, detectionClasses);
|
||||
var canvasLabel = new CanvasLabel(detection, RenderSize, videoSize, detection.Probability);
|
||||
var canvasLabel = new CanvasLabel(detection, RenderSize, videoSize, detection.Confidence);
|
||||
CreateDetectionControl(annClass, time, canvasLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDetectionControl(DetectionClass annClass, TimeSpan time, CanvasLabel canvasLabel)
|
||||
{
|
||||
var detectionControl = new DetectionControl(annClass, time, AnnotationResizeStart, canvasLabel.Probability)
|
||||
var detectionControl = new DetectionControl(annClass, time, AnnotationResizeStart, canvasLabel.Confidence)
|
||||
{
|
||||
Width = canvasLabel.Width,
|
||||
Height = canvasLabel.Height
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Width="*" Header="Назва" Binding="{Binding Path=Name}" CanUserSort="False">
|
||||
<DataGridTextColumn Width="*" Header="Назва" Binding="{Binding Path=ShortName}" CanUserSort="False">
|
||||
<DataGridTextColumn.HeaderStyle>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="Background" Value="#252525"/>
|
||||
|
||||
@@ -1,52 +1,33 @@
|
||||
using System.Windows.Media;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class AnnotationResult
|
||||
{
|
||||
public Annotation Annotation { get; set; }
|
||||
public List<(Color Color, double Confidence)> Colors { get; private set; }
|
||||
|
||||
public string ImagePath { get; set; }
|
||||
public string TimeStr { get; set; }
|
||||
|
||||
public string ClassName { get; set; }
|
||||
|
||||
public Color ClassColor0 { get; set; }
|
||||
public Color ClassColor1 { get; set; }
|
||||
public Color ClassColor2 { get; set; }
|
||||
public Color ClassColor3 { get; set; }
|
||||
|
||||
|
||||
public AnnotationResult(Dictionary<int, DetectionClass> allDetectionClasses, Annotation annotation)
|
||||
{
|
||||
|
||||
Annotation = annotation;
|
||||
var detections = annotation.Detections.ToList();
|
||||
|
||||
Color GetAnnotationClass(List<int> detectionClasses, int colorNumber)
|
||||
{
|
||||
if (detections.Count == 0)
|
||||
return (-1).ToColor();
|
||||
|
||||
return colorNumber >= detectionClasses.Count
|
||||
? allDetectionClasses[detectionClasses.LastOrDefault()].Color
|
||||
: allDetectionClasses[detectionClasses[colorNumber]].Color;
|
||||
}
|
||||
|
||||
TimeStr = $"{annotation.Time:h\\:mm\\:ss}";
|
||||
ImagePath = annotation.ImagePath;
|
||||
|
||||
var detectionClasses = detections.Select(x => x.ClassNumber).Distinct().ToList();
|
||||
var detectionClasses = annotation.Detections.Select(x => x.ClassNumber).Distinct().ToList();
|
||||
|
||||
Colors = annotation.Detections
|
||||
.Select(d => (allDetectionClasses[d.ClassNumber].Color, d.Confidence))
|
||||
.ToList();
|
||||
|
||||
ClassName = detectionClasses.Count > 1
|
||||
? string.Join(", ", detectionClasses.Select(x => allDetectionClasses[x].UIName))
|
||||
: allDetectionClasses[detectionClasses.FirstOrDefault()].UIName;
|
||||
|
||||
ClassColor0 = GetAnnotationClass(detectionClasses, 0);
|
||||
ClassColor1 = GetAnnotationClass(detectionClasses, 1);
|
||||
ClassColor2 = GetAnnotationClass(detectionClasses, 2);
|
||||
ClassColor3 = GetAnnotationClass(detectionClasses, 3);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class AnnotationConfig
|
||||
{
|
||||
Id = cls.Id,
|
||||
Name = cls.Name,
|
||||
Color = cls.Color,
|
||||
ShortName = cls.ShortName,
|
||||
PhotoMode = mode
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Windows.Media;
|
||||
using Azaion.Common.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
@@ -11,6 +10,8 @@ public class DetectionClass
|
||||
public string Name { get; set; } = null!;
|
||||
public string ShortName { get; set; } = null!;
|
||||
|
||||
public Color Color { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string UIName
|
||||
{
|
||||
@@ -31,9 +32,6 @@ public class DetectionClass
|
||||
[JsonIgnore]
|
||||
public PhotoMode PhotoMode { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Color Color => Id.ToColor();
|
||||
|
||||
[JsonIgnore] //For UI
|
||||
public int ClassNumber => Id + 1;
|
||||
|
||||
|
||||
@@ -26,22 +26,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 double? Confidence { get; }
|
||||
|
||||
public CanvasLabel()
|
||||
{
|
||||
}
|
||||
|
||||
public CanvasLabel(int classNumber, double x, double y, double width, double height, double? probability = null) : base(classNumber)
|
||||
public CanvasLabel(int classNumber, double x, double y, double width, double height, double? confidence = null) : base(classNumber)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Width = width;
|
||||
Height = height;
|
||||
Probability = probability;
|
||||
Confidence = confidence;
|
||||
}
|
||||
|
||||
public CanvasLabel(YoloLabel label, Size canvasSize, Size? videoSize = null, double? probability = null)
|
||||
public CanvasLabel(YoloLabel label, Size canvasSize, Size? videoSize = null, double confidence = 1)
|
||||
{
|
||||
var cw = canvasSize.Width;
|
||||
var ch = canvasSize.Height;
|
||||
@@ -75,7 +75,7 @@ public class CanvasLabel : Label
|
||||
Width = label.Width * realWidth;
|
||||
Height = label.Height * ch;
|
||||
}
|
||||
Probability = probability;
|
||||
Confidence = confidence;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,12 +189,12 @@ public class YoloLabel : Label
|
||||
public class Detection : YoloLabel
|
||||
{
|
||||
[JsonProperty(PropertyName = "an")][Key("an")] public string AnnotationName { get; set; } = null!;
|
||||
[JsonProperty(PropertyName = "p")][Key("p")] public double? Probability { get; set; }
|
||||
[JsonProperty(PropertyName = "p")][Key("p")] public double Confidence { get; set; }
|
||||
|
||||
//For db & serialization
|
||||
public Detection(){}
|
||||
|
||||
public Detection(string annotationName, YoloLabel label, double? probability = null)
|
||||
public Detection(string annotationName, YoloLabel label, double confidence = 1)
|
||||
{
|
||||
AnnotationName = annotationName;
|
||||
ClassNumber = label.ClassNumber;
|
||||
@@ -202,6 +202,6 @@ public class Detection : YoloLabel
|
||||
CenterY = label.CenterY;
|
||||
Height = label.Height;
|
||||
Width = label.Width;
|
||||
Probability = probability;
|
||||
Confidence = confidence;
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,12 @@ namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class ColorExtensions
|
||||
{
|
||||
public static Color ToColor(this int id)
|
||||
private const int MIN_ALPHA = 20;
|
||||
private const int MAX_ALPHA = 100;
|
||||
|
||||
public static Color ToConfidenceColor(this Color color, double confidence )
|
||||
{
|
||||
var index = id % ColorValues.Length;
|
||||
var hex = index == -1
|
||||
? "#40DDDDDD"
|
||||
: $"#40{ColorValues[index]}";
|
||||
var color =(Color)ColorConverter.ConvertFromString(hex);
|
||||
color.A = (byte)(MIN_ALPHA + (int)Math.Round(confidence * (MAX_ALPHA - MIN_ALPHA)));
|
||||
return color;
|
||||
}
|
||||
|
||||
private static readonly string[] ColorValues =
|
||||
[
|
||||
"FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000",
|
||||
"800000", "008000", "000080", "808000", "800080", "008080", "808080",
|
||||
"C00000", "00C000", "0000C0", "C0C000", "C000C0", "00C0C0", "C0C0C0",
|
||||
"400000", "004000", "000040", "404000", "400040", "004040", "404040",
|
||||
"200000", "002000", "000020", "202000", "200020", "002020", "202020",
|
||||
"600000", "006000", "000060", "606000", "600060", "006060", "606060",
|
||||
"A00000", "00A000", "0000A0", "A0A000", "A000A0", "00A0A0", "A0A0A0",
|
||||
"E00000", "00E000", "0000E0", "E0E000", "E000E0", "00E0E0", "E0E0E0"
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user