fix coma bug

add simple help window
This commit is contained in:
Oleksandr Bezdieniezhnykh
2024-05-17 01:10:50 +03:00
parent a85022c5fd
commit 6c2e46552a
6 changed files with 127 additions and 14 deletions
@@ -17,6 +17,7 @@ public partial class App : Application
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddSingleton<MainWindow>(); services.AddSingleton<MainWindow>();
services.AddSingleton<HelpWindow>();
services.AddMediatR(c => c.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); services.AddMediatR(c => c.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
services.AddSingleton<LibVLC>(_ => new LibVLC()); services.AddSingleton<LibVLC>(_ => new LibVLC());
services.AddSingleton<FormState>(); services.AddSingleton<FormState>();
@@ -1,4 +1,5 @@
using System.Windows; using System.Globalization;
using System.Windows;
namespace Azaion.Annotator.DTO; namespace Azaion.Annotator.DTO;
@@ -20,7 +21,15 @@ public class AnnotationInfo
Height = height; 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) public AnnotationInfo ToLabelCoordinates(Size canvasSize, Size videoSize)
{ {
@@ -96,20 +105,21 @@ public class AnnotationInfo
if (s == null || string.IsNullOrEmpty(s)) if (s == null || string.IsNullOrEmpty(s))
return null; return null;
var strs = s.Split(' '); var strs = s.Replace(',','.').Split(' ');
if (strs.Length != 5) if (strs.Length != 5)
return null; return null;
try try
{ {
return new AnnotationInfo var res = new AnnotationInfo
{ {
ClassNumber = int.Parse(strs[0]), ClassNumber = int.Parse(strs[0], CultureInfo.InvariantCulture),
X = double.Parse(strs[1]), X = double.Parse(strs[1], CultureInfo.InvariantCulture),
Y = double.Parse(strs[2]), Y = double.Parse(strs[2], CultureInfo.InvariantCulture),
Width = double.Parse(strs[3]), Width = double.Parse(strs[3], CultureInfo.InvariantCulture),
Height = double.Parse(strs[4]) Height = double.Parse(strs[4], CultureInfo.InvariantCulture)
}; };
return res;
} }
catch (Exception) catch (Exception)
{ {
@@ -25,6 +25,7 @@ public class Config
public List<AnnotationClass> AnnotationClasses { get; set; } = []; public List<AnnotationClass> AnnotationClasses { get; set; } = [];
public Size WindowSize { get; set; } public Size WindowSize { get; set; }
public Point WindowLocation { get; set; } public Point WindowLocation { get; set; }
public bool ShowHelpOnStart { get; set; }
public void Save() public void Save()
{ {
@@ -42,7 +43,8 @@ public class Config
LabelsDirectory = Path.Combine(exePath, DEFAULT_LABELS_DIR), LabelsDirectory = Path.Combine(exePath, DEFAULT_LABELS_DIR),
ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR), ImagesDirectory = Path.Combine(exePath, DEFAULT_IMAGES_DIR),
WindowLocation = DefaultWindowLocation, WindowLocation = DefaultWindowLocation,
WindowSize = DefaultWindowSize WindowSize = DefaultWindowSize,
ShowHelpOnStart = true
}; };
} }
try try
@@ -0,0 +1,49 @@
<Window x:Class="Azaion.Annotator.HelpWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Azaion.Annotator"
mc:Ignorable="d"
Title="HelpWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap" FontSize="18" >
Анотація - це виділений на кадрі відео об'єкт з якимось класом (Броньована техніка, вантажівка, тощо)
</TextBlock>
<TextBlock Grid.Row="1" TextWrapping="Wrap" FontSize="18" >
1. Анотації мусять містити об'єкти найкращої чіткості та якості. Сильно розмазані чи задимлені об'єкти не підходять
</TextBlock>
<TextBlock Grid.Row="2" TextWrapping="Wrap" FontSize="18" >
2. Чим більше ракурсів одного і того самого об'єкту - тим краще. Наприклад, якщо на відео об'єкт малий, а далі на нього наводиться камера, то треба анотувати як малий об'єкт, так і великий. Якщо об'єкт статичний і ракурс не змінюється, достатньо одної анотації, а якщо рухається, і видно об'єкт з різних боків - то треба кілька, по 1 на ракурс
</TextBlock>
<TextBlock Grid.Row="3" TextWrapping="Wrap" FontSize="18" >
3. Анотація об'єктів з формою що суттєво відрізняється від прямокутника. Наприклад, якщо танк має довге дуло, саме дуло не треба виділяти, оскільки попадає в анотацію дуже багато зайвого. Те ж саме з окопами - якщо окопи займають візуально багато місця, і в квадрат буде попадати багато зайвого, то краще зробити декілька малих анотацій саме окопів
</TextBlock>
<TextBlock Grid.Row="4" TextWrapping="Wrap" FontSize="18" >
4. Будь-які існуючі позначки на відео, OSD і інше не мусять бути в анотаціях. Анотація мусить мати лише конкретний об'єкт без ліній на ньому
</TextBlock>
<TextBlock Grid.Row="5" TextWrapping="Wrap" FontSize="18" >
5. До кожного відео мусить бути декілька фоток без анотацій, для гарнішого навчання
</TextBlock>
<TextBlock Grid.Row="6" TextWrapping="Wrap" FontSize="18" >
6. Артилерія - це гармати, міномети. Якщо це САУ наприклад, або будь що на гусеничній техніці, це Броньована техніка.
</TextBlock>
<CheckBox Grid.Row="7" x:Name="CbShowHelp" IsChecked="{Binding Path=ShowHelpOnStart}">
Показувати при запуску
</CheckBox>
<Button Grid.Row="8" Click="Close" IsEnabledChanged="UIElement_OnIsEnabledChanged">
Закрити
</Button>
</Grid>
</Window>
@@ -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;
}
}
@@ -3,6 +3,8 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using Azaion.Annotator.DTO; using Azaion.Annotator.DTO;
using Azaion.Annotator.Extensions; using Azaion.Annotator.Extensions;
using LibVLCSharp.Shared; using LibVLCSharp.Shared;
@@ -19,6 +21,7 @@ public partial class MainWindow
private readonly FormState _formState; private readonly FormState _formState;
private readonly Config _config; private readonly Config _config;
private readonly HelpWindow _helpWindow;
private readonly TimeSpan _annotationTime = TimeSpan.FromSeconds(1); private readonly TimeSpan _annotationTime = TimeSpan.FromSeconds(1);
public ObservableCollection<AnnotationClass> AnnotationClasses { get; set; } public ObservableCollection<AnnotationClass> AnnotationClasses { get; set; }
@@ -26,10 +29,13 @@ public partial class MainWindow
public Dictionary<string, List<AnnotationInfo>> Annotations { get; set; } = new(); public Dictionary<string, List<AnnotationInfo>> Annotations { get; set; } = new();
public bool ShowHelpOnStart { get; set; }
public MainWindow(LibVLC libVLC, MediaPlayer mediaPlayer, public MainWindow(LibVLC libVLC, MediaPlayer mediaPlayer,
IMediator mediator, IMediator mediator,
FormState formState, FormState formState,
Config config) Config config,
HelpWindow helpWindow)
{ {
InitializeComponent(); InitializeComponent();
_libVLC = libVLC; _libVLC = libVLC;
@@ -37,6 +43,7 @@ public partial class MainWindow
_mediator = mediator; _mediator = mediator;
_formState = formState; _formState = formState;
_config = config; _config = config;
_helpWindow = helpWindow;
VideoView.Loaded += VideoView_Loaded; VideoView.Loaded += VideoView_Loaded;
Closed += OnFormClosed; Closed += OnFormClosed;
@@ -64,6 +71,21 @@ public partial class MainWindow
if (LvFiles.Items.IsEmpty) if (LvFiles.Items.IsEmpty)
BlinkHelp(HelpTexts.HelpTextsDict[HelpTextEnum.Initial]); 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) 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 => Annotations = files.ToDictionary(f => Path.GetFileNameWithoutExtension(f.Name), f =>
{ {
var str = File.ReadAllText(f.FullName); 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();
})!; })!;
} }