mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:36:30 +00:00
fix bug with annotation result gradient stops
add tensorrt engine
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user