mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:36:29 +00:00
fix detection label
fix schema migrator for enums
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.Extensions;
|
||||
using Label = System.Windows.Controls.Label;
|
||||
using Annotation = Azaion.Common.Database.Annotation;
|
||||
|
||||
namespace Azaion.Common.Controls;
|
||||
|
||||
@@ -94,7 +94,8 @@ public class DetectionControl : Border
|
||||
};
|
||||
_detectionLabelPanel = new DetectionLabelPanel
|
||||
{
|
||||
Confidence = canvasLabel.Confidence
|
||||
Confidence = canvasLabel.Confidence,
|
||||
DetectionClass = Annotation.DetectionClassesDict[canvasLabel.ClassNumber]
|
||||
};
|
||||
|
||||
DetectionLabelContainer.Children.Add(_detectionLabelPanel);
|
||||
|
||||
@@ -47,13 +47,13 @@
|
||||
</DrawingImage>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid x:Name="DetectionGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="28"></ColumnDefinition>
|
||||
<ColumnDefinition Width="2"></ColumnDefinition>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Grid.Column="0" x:Name="AffiliationImage">
|
||||
</Image>
|
||||
<Label Grid.Column="1" FontSize="16"></Label>
|
||||
<Label Grid.Column="1" x:Name="DetectionClassName" FontSize="16"></Label>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Windows.Media;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.Extensions;
|
||||
|
||||
namespace Azaion.Common.Controls
|
||||
{
|
||||
public partial class DetectionLabelPanel
|
||||
{
|
||||
private AffiliationEnum _affiliation = AffiliationEnum.None;
|
||||
private double _confidence;
|
||||
|
||||
public AffiliationEnum Affiliation
|
||||
{
|
||||
@@ -18,18 +18,33 @@ namespace Azaion.Common.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public DetectionClass DetectionClass { get; set; }
|
||||
private DetectionClass _detectionClass = new();
|
||||
public DetectionClass DetectionClass {
|
||||
get => _detectionClass;
|
||||
set
|
||||
{
|
||||
_detectionClass = value;
|
||||
SetClassName();
|
||||
}
|
||||
}
|
||||
|
||||
private double _confidence;
|
||||
public double Confidence
|
||||
{
|
||||
get => _confidence;
|
||||
set
|
||||
{
|
||||
_confidence = value;
|
||||
|
||||
SetClassName();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetClassName()
|
||||
{
|
||||
DetectionClassName.Content = _confidence >= 0.995 ? _detectionClass.UIName : $"{_detectionClass.UIName}: {_confidence * 100:F0}%";
|
||||
DetectionGrid.Background = new SolidColorBrush(_detectionClass.Color.ToConfidenceColor(_confidence));
|
||||
}
|
||||
|
||||
public DetectionLabelPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
@@ -225,6 +225,7 @@ public class Detection : YoloLabel
|
||||
[JsonProperty(PropertyName = "an")][Key("an")] public string AnnotationName { get; set; } = null!;
|
||||
[JsonProperty(PropertyName = "p")][Key("p")] public double Confidence { get; set; }
|
||||
[JsonProperty(PropertyName = "dn")][Key("dn")] public string Description { get; set; }
|
||||
[JsonProperty(PropertyName = "af")][Key("af")] public AffiliationEnum Affiliation { get; set; }
|
||||
|
||||
//For db & serialization
|
||||
public Detection(){}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.DTO.Queue;
|
||||
using MessagePack;
|
||||
|
||||
@@ -13,14 +12,14 @@ public class Annotation
|
||||
private static string _labelsDir = null!;
|
||||
private static string _imagesDir = null!;
|
||||
private static string _thumbDir = null!;
|
||||
private static Dictionary<int, DetectionClass> _detectionClassesDict;
|
||||
public static Dictionary<int, DetectionClass> DetectionClassesDict = null!;
|
||||
|
||||
public static void Init(DirectoriesConfig config, Dictionary<int, DetectionClass> detectionClassesDict)
|
||||
{
|
||||
_labelsDir = config.LabelsDirectory;
|
||||
_imagesDir = config.ImagesDirectory;
|
||||
_thumbDir = config.ThumbnailsDirectory;
|
||||
_detectionClassesDict = detectionClassesDict;
|
||||
DetectionClassesDict = detectionClassesDict;
|
||||
}
|
||||
|
||||
[Key("n")] public string Name { get; set; } = null!;
|
||||
@@ -76,7 +75,7 @@ public class Annotation
|
||||
|
||||
private List<(Color Color, double Confidence)>? _colors;
|
||||
[IgnoreMember] public List<(Color Color, double Confidence)> Colors => _colors ??= Detections
|
||||
.Select(d => (_detectionClassesDict[d.ClassNumber].Color, d.Confidence))
|
||||
.Select(d => (DetectionClassesDict[d.ClassNumber].Color, d.Confidence))
|
||||
.ToList();
|
||||
|
||||
private string _className;
|
||||
@@ -88,8 +87,8 @@ public class Annotation
|
||||
{
|
||||
var detectionClasses = Detections.Select(x => x.ClassNumber).Distinct().ToList();
|
||||
_className = detectionClasses.Count > 1
|
||||
? string.Join(", ", detectionClasses.Select(x => _detectionClassesDict[x].UIName))
|
||||
: _detectionClassesDict[detectionClasses.FirstOrDefault()].UIName;
|
||||
? string.Join(", ", detectionClasses.Select(x => DetectionClassesDict[x].UIName))
|
||||
: DetectionClassesDict[detectionClasses.FirstOrDefault()].UIName;
|
||||
}
|
||||
return _className;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@ public static class SchemaMigrator
|
||||
if (underlyingType == typeof(bool))
|
||||
return $"NOT NULL DEFAULT {(Convert.ToBoolean(defaultValue) ? 1 : 0)}";
|
||||
|
||||
if (underlyingType.IsEnum)
|
||||
return $"NOT NULL DEFAULT {(int)defaultValue}";
|
||||
|
||||
if (underlyingType.IsValueType && defaultValue is IFormattable f)
|
||||
return $"NOT NULL DEFAULT {f.ToString(null, System.Globalization.CultureInfo.InvariantCulture)}";
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static T GetValueOrDefault<T>(this string value, T defaultValue) where T : struct
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return defaultValue;
|
||||
|
||||
return Enum.TryParse(value, true, out T result) ? result : defaultValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user