mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 17:46:36 +00:00
lot of small fixes for dataset explorer
This commit is contained in:
@@ -23,25 +23,24 @@ public partial class DatasetExplorer
|
||||
|
||||
private int _tempSelectedClassIdx = 0;
|
||||
private readonly string _thumbnailsCacheFile;
|
||||
private IConfigRepository _configRepository;
|
||||
private readonly IConfigRepository _configRepository;
|
||||
private readonly FormState _formState;
|
||||
private readonly IGalleryManager _galleryManager;
|
||||
private static Dictionary<string, List<int>> LabelsCache { get; set; } = new();
|
||||
|
||||
public bool ThumbnailLoading { get; set; }
|
||||
|
||||
public ThumbnailDto? CurrentThumbnail { get; set; }
|
||||
|
||||
public DatasetExplorer(
|
||||
Config config,
|
||||
ILogger<DatasetExplorer> logger,
|
||||
IConfigRepository configRepository,
|
||||
FormState formState,
|
||||
IGalleryManager galleryManager)
|
||||
FormState formState)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_configRepository = configRepository;
|
||||
_formState = formState;
|
||||
_galleryManager = galleryManager;
|
||||
_thumbnailsCacheFile = Path.Combine(config.ThumbnailsDirectory, Config.ThumbnailsCacheFile);
|
||||
if (File.Exists(_thumbnailsCacheFile))
|
||||
{
|
||||
@@ -116,33 +115,12 @@ public partial class DatasetExplorer
|
||||
};
|
||||
ThumbnailsView.MouseDoubleClick += async (_, _) => await EditAnnotation();
|
||||
|
||||
Activated += (_, _) => { _formState.ActiveWindow = WindowsEnum.DatasetExplorer; };
|
||||
|
||||
ExplorerEditor.GetTimeFunc = () => _formState.GetTime(CurrentThumbnail!.ImagePath)!.Value;
|
||||
}
|
||||
|
||||
private async Task EditAnnotation()
|
||||
{
|
||||
if (ThumbnailsView.SelectedItem == null)
|
||||
return;
|
||||
|
||||
var dto = (ThumbnailsView.SelectedItem as ThumbnailDto)!;
|
||||
ExplorerEditor.Background = new ImageBrush
|
||||
ThumbnailsView.SelectionChanged += (_, _) =>
|
||||
{
|
||||
ImageSource = new BitmapImage(new Uri(dto.ImagePath))
|
||||
StatusText.Text = $"Обрано: {ThumbnailsView.SelectedItems.Count} | {ThumbnailsView.SelectedIndex} / {ThumbnailsDtos.Count}";
|
||||
};
|
||||
CurrentThumbnail = dto;
|
||||
|
||||
Switcher.SelectedIndex = 1;
|
||||
LvClasses.SelectedIndex = 1;
|
||||
|
||||
var time = _formState.GetTime(dto.ImagePath)!.Value;
|
||||
foreach (var ann in await YoloLabel.ReadFromFile(dto.LabelPath))
|
||||
{
|
||||
var annClass = _config.AnnotationClasses[ann.ClassNumber];
|
||||
var annInfo = new CanvasLabel(ann, ExplorerEditor.RenderSize, ExplorerEditor.RenderSize);
|
||||
Dispatcher.Invoke(() => ExplorerEditor.CreateAnnotation(annClass, time, annInfo));
|
||||
}
|
||||
Activated += (_, _) => { _formState.ActiveWindow = WindowsEnum.DatasetExplorer; };
|
||||
|
||||
Switcher.SelectionChanged += (sender, args) =>
|
||||
{
|
||||
@@ -157,8 +135,53 @@ public partial class DatasetExplorer
|
||||
//Explorer
|
||||
LvClasses.ItemsSource = AllAnnotationClasses;
|
||||
LvClasses.SelectedIndex = _tempSelectedClassIdx;
|
||||
ExplorerEditor.Background = null;
|
||||
}
|
||||
};
|
||||
|
||||
ExplorerEditor.GetTimeFunc = () => _formState.GetTime(CurrentThumbnail!.ImagePath)!.Value;
|
||||
}
|
||||
|
||||
private async Task EditAnnotation()
|
||||
{
|
||||
try
|
||||
{
|
||||
ThumbnailLoading = true;
|
||||
|
||||
if (ThumbnailsView.SelectedItem == null)
|
||||
return;
|
||||
|
||||
var dto = (ThumbnailsView.SelectedItem as ThumbnailDto)!;
|
||||
CurrentThumbnail = dto;
|
||||
ExplorerEditor.Background = new ImageBrush
|
||||
{
|
||||
ImageSource = await dto.ImagePath.OpenImage()
|
||||
};
|
||||
|
||||
Switcher.SelectedIndex = 1;
|
||||
LvClasses.SelectedIndex = 1;
|
||||
|
||||
var time = _formState.GetTime(dto.ImagePath)!.Value;
|
||||
ExplorerEditor.RemoveAllAnns();
|
||||
foreach (var ann in await YoloLabel.ReadFromFile(dto.LabelPath))
|
||||
{
|
||||
var annClass = _config.AnnotationClasses[ann.ClassNumber];
|
||||
var annInfo = new CanvasLabel(ann, ExplorerEditor.RenderSize, ExplorerEditor.RenderSize);
|
||||
ExplorerEditor.CreateAnnotation(annClass, time, annInfo);
|
||||
}
|
||||
|
||||
ThumbnailLoading = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ThumbnailLoading = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task SaveUserSettings()
|
||||
@@ -173,6 +196,7 @@ public partial class DatasetExplorer
|
||||
|
||||
private void DeleteAnnotations()
|
||||
{
|
||||
var tempSelected = ThumbnailsView.SelectedIndex;
|
||||
var result = MessageBox.Show("Чи дійсно видалити аннотації?","Підтвердження видалення", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
@@ -186,6 +210,7 @@ public partial class DatasetExplorer
|
||||
File.Delete(dto.ThumbnailPath);
|
||||
ThumbnailsDtos.Remove(dto);
|
||||
}
|
||||
ThumbnailsView.SelectedIndex = Math.Min(ThumbnailsDtos.Count, tempSelected);
|
||||
}
|
||||
|
||||
private async Task ReloadThumbnails()
|
||||
@@ -212,11 +237,14 @@ public partial class DatasetExplorer
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(thumbnail)[..^Config.ThumbnailPrefix.Length];
|
||||
var imageName = Path.Combine(_config.ImagesDirectory, name);
|
||||
foreach (var imageFormat in _config.ImageFormats)
|
||||
foreach (var f in _config.ImageFormats)
|
||||
{
|
||||
imageName = $"{imageName}.{imageFormat}";
|
||||
if (File.Exists(imageName))
|
||||
var curName = $"{imageName}.{f}";
|
||||
if (File.Exists(curName))
|
||||
{
|
||||
imageName = curName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var labelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt");
|
||||
|
||||
Reference in New Issue
Block a user