make thumbnail generating multithread

fix the bug with open video
add class distribution chart
This commit is contained in:
Alex Bezdieniezhnykh
2024-09-25 21:46:07 +03:00
parent 742f1ffee9
commit 22d4493d86
11 changed files with 215 additions and 50 deletions
+53 -16
View File
@@ -7,6 +7,8 @@ using Azaion.Annotator.DTO;
using Azaion.Annotator.Extensions;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using ScottPlot;
using Color = ScottPlot.Color;
using MessageBox = System.Windows.MessageBox;
namespace Azaion.Annotator;
@@ -48,7 +50,6 @@ public partial class DatasetExplorer
}
InitializeComponent();
DataContext = this;
Loaded += async (_, _) =>
{
AllAnnotationClasses = new ObservableCollection<AnnotationClass>(
@@ -88,12 +89,14 @@ public partial class DatasetExplorer
LvClasses.SelectedIndex = config.LastSelectedExplorerClass ?? 0;
ExplorerEditor.CurrentAnnClass = (AnnotationClass)LvClasses.SelectedItem;
await ReloadThumbnails();
LoadClassDistribution();
SizeChanged += async (_, _) => await SaveUserSettings();
LocationChanged += async (_, _) => await SaveUserSettings();
StateChanged += async (_, _) => await SaveUserSettings();
RefreshThumbBar.Value = galleryManager.ThumbnailsPercentage;
DataContext = this;
};
Closing += (sender, args) =>
@@ -125,18 +128,17 @@ public partial class DatasetExplorer
Switcher.SelectionChanged += (sender, args) =>
{
if (Switcher.SelectedIndex == 1)
switch (Switcher.SelectedIndex)
{
//Editor
_tempSelectedClassIdx = LvClasses.SelectedIndex;
LvClasses.ItemsSource = _config.AnnotationClasses;
}
else
{
//Explorer
LvClasses.ItemsSource = AllAnnotationClasses;
LvClasses.SelectedIndex = _tempSelectedClassIdx;
ExplorerEditor.Background = null;
case 0: //ListView
LvClasses.ItemsSource = AllAnnotationClasses;
LvClasses.SelectedIndex = _tempSelectedClassIdx;
ExplorerEditor.Background = null;
break;
case 1: //Editor
_tempSelectedClassIdx = LvClasses.SelectedIndex;
LvClasses.ItemsSource = _config.AnnotationClasses;
break;
}
};
@@ -148,6 +150,41 @@ public partial class DatasetExplorer
}
private void LoadClassDistribution()
{
var data = LabelsCache.SelectMany(x => x.Value)
.GroupBy(x => x)
.Select(x => new
{
x.Key,
_config.AnnotationClassesDict[x.Key].Name,
_config.AnnotationClassesDict[x.Key].Color,
ClassCount = x.Count()
})
.ToList();
var plot = ClassDistribution.Plot;
plot.Add.Bars(data.Select(x => new Bar
{
Orientation = Orientation.Horizontal,
Position = -1.5 * x.Key + 1,
Label = x.ClassCount > 200 ? x.ClassCount.ToString() : "",
FillColor = new Color(x.Color.R, x.Color.G, x.Color.B, x.Color.A),
Value = x.ClassCount,
CenterLabel = true
}));
foreach (var x in data)
{
var label = plot.Add.Text(x.Name, 50, -1.5 * x.Key + 1.1);
label.LabelFontSize = 16;
}
plot.Axes.AutoScale();
//plot.Axes.SetLimits(-200, data.Max(x => x.ClassCount + 3000), -2 * data.Count + 5, 5);
ClassDistribution.Background = new SolidColorBrush(System.Windows.Media.Colors.Black);
ClassDistribution.Refresh();
}
private async Task EditAnnotation()
{
try
@@ -171,7 +208,7 @@ public partial class DatasetExplorer
ExplorerEditor.RemoveAllAnns();
foreach (var ann in await YoloLabel.ReadFromFile(dto.LabelPath))
{
var annClass = _config.AnnotationClasses[ann.ClassNumber];
var annClass = _config.AnnotationClassesDict[ann.ClassNumber];
var annInfo = new CanvasLabel(ann, ExplorerEditor.RenderSize, ExplorerEditor.RenderSize);
ExplorerEditor.CreateAnnotation(annClass, time, annInfo);
}
@@ -248,7 +285,7 @@ public partial class DatasetExplorer
await File.WriteAllTextAsync(_thumbnailsCacheFile, JsonConvert.SerializeObject(LabelsCache));
}
private async Task AddThumbnail(string thumbnail)
private async Task AddThumbnail(string thumbnail, CancellationToken cancellationToken = default)
{
try
{
@@ -284,7 +321,7 @@ public partial class DatasetExplorer
return;
}
var labels = await YoloLabel.ReadFromFile(labelPath);
var labels = await YoloLabel.ReadFromFile(labelPath, cancellationToken);
classes = labels.Select(x => x.ClassNumber).Distinct().ToList();
LabelsCache.Add(name, classes);
}