From 6c2e46552ade83643b28b9f5719acf45d30f3207 Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Fri, 17 May 2024 01:10:50 +0300 Subject: [PATCH] fix coma bug add simple help window --- Azaion.Annotator/Azaion.Annotator/App.xaml.cs | 1 + .../Azaion.Annotator/DTO/AnnotationInfo.cs | 28 +++++++---- .../Azaion.Annotator/DTO/Config.cs | 6 ++- .../Azaion.Annotator/HelpWindow.xaml | 49 +++++++++++++++++++ .../Azaion.Annotator/HelpWindow.xaml.cs | 27 ++++++++++ .../Azaion.Annotator/MainWindow.xaml.cs | 30 ++++++++++-- 6 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml create mode 100644 Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml.cs diff --git a/Azaion.Annotator/Azaion.Annotator/App.xaml.cs b/Azaion.Annotator/Azaion.Annotator/App.xaml.cs index 73a228b..8be5352 100644 --- a/Azaion.Annotator/Azaion.Annotator/App.xaml.cs +++ b/Azaion.Annotator/Azaion.Annotator/App.xaml.cs @@ -17,6 +17,7 @@ public partial class App : Application { var services = new ServiceCollection(); services.AddSingleton(); + services.AddSingleton(); services.AddMediatR(c => c.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); services.AddSingleton(_ => new LibVLC()); services.AddSingleton(); diff --git a/Azaion.Annotator/Azaion.Annotator/DTO/AnnotationInfo.cs b/Azaion.Annotator/Azaion.Annotator/DTO/AnnotationInfo.cs index fa5b0e7..19e6574 100644 --- a/Azaion.Annotator/Azaion.Annotator/DTO/AnnotationInfo.cs +++ b/Azaion.Annotator/Azaion.Annotator/DTO/AnnotationInfo.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Globalization; +using System.Windows; namespace Azaion.Annotator.DTO; @@ -20,7 +21,15 @@ public class AnnotationInfo Height = height; } - public override string ToString() => $"{ClassNumber} {X:F5} {Y:F5} {Width:F5} {Height:F5}"; + public override string ToString() => string.Concat(ClassNumber.ToString(), + " ", + X.ToString("F5", CultureInfo.InvariantCulture), + " ", + Y.ToString("F5", CultureInfo.InvariantCulture), + " ", + Width.ToString("F5", CultureInfo.InvariantCulture), + " ", + Height.ToString("F5", CultureInfo.InvariantCulture)); public AnnotationInfo ToLabelCoordinates(Size canvasSize, Size videoSize) { @@ -96,20 +105,21 @@ public class AnnotationInfo if (s == null || string.IsNullOrEmpty(s)) return null; - var strs = s.Split(' '); + var strs = s.Replace(',','.').Split(' '); if (strs.Length != 5) return null; try { - return new AnnotationInfo + var res = new AnnotationInfo { - ClassNumber = int.Parse(strs[0]), - X = double.Parse(strs[1]), - Y = double.Parse(strs[2]), - Width = double.Parse(strs[3]), - Height = double.Parse(strs[4]) + ClassNumber = int.Parse(strs[0], CultureInfo.InvariantCulture), + X = double.Parse(strs[1], CultureInfo.InvariantCulture), + Y = double.Parse(strs[2], CultureInfo.InvariantCulture), + Width = double.Parse(strs[3], CultureInfo.InvariantCulture), + Height = double.Parse(strs[4], CultureInfo.InvariantCulture) }; + return res; } catch (Exception) { diff --git a/Azaion.Annotator/Azaion.Annotator/DTO/Config.cs b/Azaion.Annotator/Azaion.Annotator/DTO/Config.cs index ee2d0d7..45c5500 100644 --- a/Azaion.Annotator/Azaion.Annotator/DTO/Config.cs +++ b/Azaion.Annotator/Azaion.Annotator/DTO/Config.cs @@ -25,7 +25,8 @@ public class Config public List AnnotationClasses { get; set; } = []; public Size WindowSize { get; set; } public Point WindowLocation { get; set; } - + public bool ShowHelpOnStart { get; set; } + public void Save() { File.WriteAllText(CONFIG_PATH, JsonConvert.SerializeObject(this, Formatting.Indented), Encoding.UTF8); @@ -42,7 +43,8 @@ public class Config LabelsDirectory = Path.Combine(exePath, DEFAULT_LABELS_DIR), ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR), WindowLocation = DefaultWindowLocation, - WindowSize = DefaultWindowSize + WindowSize = DefaultWindowSize, + ShowHelpOnStart = true }; } try diff --git a/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml b/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml new file mode 100644 index 0000000..06fba62 --- /dev/null +++ b/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + Анотація - це виділений на кадрі відео об'єкт з якимось класом (Броньована техніка, вантажівка, тощо) + + + 1. Анотації мусять містити об'єкти найкращої чіткості та якості. Сильно розмазані чи задимлені об'єкти не підходять + + + 2. Чим більше ракурсів одного і того самого об'єкту - тим краще. Наприклад, якщо на відео об'єкт малий, а далі на нього наводиться камера, то треба анотувати як малий об'єкт, так і великий. Якщо об'єкт статичний і ракурс не змінюється, достатньо одної анотації, а якщо рухається, і видно об'єкт з різних боків - то треба кілька, по 1 на ракурс + + + 3. Анотація об'єктів з формою що суттєво відрізняється від прямокутника. Наприклад, якщо танк має довге дуло, саме дуло не треба виділяти, оскільки попадає в анотацію дуже багато зайвого. Те ж саме з окопами - якщо окопи займають візуально багато місця, і в квадрат буде попадати багато зайвого, то краще зробити декілька малих анотацій саме окопів + + + 4. Будь-які існуючі позначки на відео, OSD і інше не мусять бути в анотаціях. Анотація мусить мати лише конкретний об'єкт без ліній на ньому + + + 5. До кожного відео мусить бути декілька фоток без анотацій, для гарнішого навчання + + + 6. Артилерія - це гармати, міномети. Якщо це САУ наприклад, або будь що на гусеничній техніці, це Броньована техніка. + + + Показувати при запуску + + + + diff --git a/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml.cs b/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml.cs new file mode 100644 index 0000000..cc8a8ec --- /dev/null +++ b/Azaion.Annotator/Azaion.Annotator/HelpWindow.xaml.cs @@ -0,0 +1,27 @@ +using System.Windows; +using Azaion.Annotator.DTO; + +namespace Azaion.Annotator; + +public partial class HelpWindow : Window +{ + public bool ShowHelpOnStart { get; set; } + private readonly Config _config; + + public HelpWindow(Config config) + { + _config = config; + ShowHelpOnStart = config.ShowHelpOnStart; + InitializeComponent(); + } + + private void Close(object sender, RoutedEventArgs e) + { + Close(); + } + + private void UIElement_OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) + { + _config.ShowHelpOnStart = CbShowHelp.IsChecked ?? true; + } +} \ No newline at end of file diff --git a/Azaion.Annotator/Azaion.Annotator/MainWindow.xaml.cs b/Azaion.Annotator/Azaion.Annotator/MainWindow.xaml.cs index aacb45b..e26df08 100644 --- a/Azaion.Annotator/Azaion.Annotator/MainWindow.xaml.cs +++ b/Azaion.Annotator/Azaion.Annotator/MainWindow.xaml.cs @@ -3,6 +3,8 @@ using System.Globalization; using System.IO; using System.Reflection; using System.Windows; +using System.Windows.Forms; +using System.Windows.Threading; using Azaion.Annotator.DTO; using Azaion.Annotator.Extensions; using LibVLCSharp.Shared; @@ -19,6 +21,7 @@ public partial class MainWindow private readonly FormState _formState; private readonly Config _config; + private readonly HelpWindow _helpWindow; private readonly TimeSpan _annotationTime = TimeSpan.FromSeconds(1); public ObservableCollection AnnotationClasses { get; set; } @@ -26,10 +29,13 @@ public partial class MainWindow public Dictionary> Annotations { get; set; } = new(); + public bool ShowHelpOnStart { get; set; } + public MainWindow(LibVLC libVLC, MediaPlayer mediaPlayer, IMediator mediator, FormState formState, - Config config) + Config config, + HelpWindow helpWindow) { InitializeComponent(); _libVLC = libVLC; @@ -37,7 +43,8 @@ public partial class MainWindow _mediator = mediator; _formState = formState; _config = config; - + _helpWindow = helpWindow; + VideoView.Loaded += VideoView_Loaded; Closed += OnFormClosed; } @@ -64,6 +71,21 @@ public partial class MainWindow if (LvFiles.Items.IsEmpty) BlinkHelp(HelpTexts.HelpTextsDict[HelpTextEnum.Initial]); + + ShowHelpOnStart = _config.ShowHelpOnStart; + if (ShowHelpOnStart) + { + _helpWindow.Show(); + _ = Task.Run(() => + { + Task.Delay(300); + Dispatcher.Invoke(() => + { + _helpWindow.Activate(); + }); + }); + } + } public void BlinkHelp(string helpText, int times = 3) @@ -169,7 +191,9 @@ public partial class MainWindow Annotations = files.ToDictionary(f => Path.GetFileNameWithoutExtension(f.Name), f => { var str = File.ReadAllText(f.FullName); - return str.Split(Environment.NewLine).Select(AnnotationInfo.Parse).ToList(); + return str.Split(Environment.NewLine).Select(AnnotationInfo.Parse) + .Where(x => x != null) + .ToList(); })!; }