add ai recognition: stage 1, works, but doesn't show

This commit is contained in:
Alex Bezdieniezhnykh
2024-10-25 00:17:24 +03:00
parent d2186eb326
commit 596f6db217
13 changed files with 591 additions and 336 deletions
+27 -25
View File
@@ -83,15 +83,7 @@ public partial class MainWindow
{
Core.Initialize();
InitControls();
_ = Task.Run(async () =>
{
while (true)
{
await _galleryManager.RefreshThumbnails();
await Task.Delay(30000);
}
});
_ = Task.Run(async () => await _galleryManager.RefreshThumbnails());
_suspendLayout = true;
@@ -123,10 +115,10 @@ public partial class MainWindow
LvClasses.ItemsSource = AnnotationClasses;
LvClasses.SelectedIndex = 0;
if (LvFiles.Items.IsEmpty)
if (LvFiles.Items.IsEmpty)
BlinkHelp(HelpTexts.HelpTextsDict[HelpTextEnum.Initial]);
if (_config.ShowHelpOnStart)
if (_config.ShowHelpOnStart)
_helpWindow.Show();
}
@@ -141,6 +133,7 @@ public partial class MainWindow
Dispatcher.Invoke(() => StatusHelp.Text = "");
await Task.Delay(200);
}
Dispatcher.Invoke(() => StatusHelp.Text = helpText);
});
}
@@ -171,7 +164,7 @@ public partial class MainWindow
};
LvFiles.MouseDoubleClick += async (_, _) => await _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Play));
LvClasses.SelectionChanged += (_, _) =>
{
var selectedClass = (AnnotationClass)LvClasses.SelectedItem;
@@ -194,7 +187,7 @@ public partial class MainWindow
SizeChanged += async (_, _) => await SaveUserSettings();
LocationChanged += async (_, _) => await SaveUserSettings();
StateChanged += async (_, _) => await SaveUserSettings();
Editor.FormState = _formState;
Editor.Mediator = _mediator;
DgAnnotations.ItemsSource = _formState.AnnotationResults;
@@ -243,13 +236,13 @@ public partial class MainWindow
var labelDir = new DirectoryInfo(_config.LabelsDirectory);
if (!labelDir.Exists)
return;
var labelFiles = labelDir.GetFiles($"{_formState.VideoName}_??????.txt");
foreach (var file in labelFiles)
{
var name = Path.GetFileNameWithoutExtension(file.Name);
var time = _formState.GetTime(name);
await AddAnnotation(time, await YoloLabel.ReadFromFile(file.FullName));
await AddAnnotation(time, await YoloLabel.ReadFromFile(file.FullName, cancellationToken));
}
}
@@ -267,11 +260,11 @@ public partial class MainWindow
_formState.AnnotationResults.Remove(existingResult);
var dict = _formState.AnnotationResults
.Select((x,i) => new { x.Time, Index = i })
.Select((x, i) => new { x.Time, Index = i })
.ToDictionary(x => x.Time, x => x.Index);
var index = dict.Where(x => x.Key < timeValue)
.OrderBy(x => x.Key - timeValue)
.OrderBy(x => timeValue - x.Key)
.Select(x => x.Value + 1)
.FirstOrDefault();
@@ -299,7 +292,7 @@ public partial class MainWindow
var videoFiles = dir.GetFiles(_config.VideoFormats.ToArray()).Select(x =>
{
var media = new Media(_libVLC, x.FullName);
using var media = new Media(_libVLC, x.FullName);
media.Parse();
var fInfo = new MediaFileInfo
{
@@ -325,7 +318,7 @@ public partial class MainWindow
TbFolder.Text = _config.VideosDirectory;
BlinkHelp(AllMediaFiles.Count == 0
? HelpTexts.HelpTextsDict[HelpTextEnum.Initial]
? HelpTexts.HelpTextsDict[HelpTextEnum.Initial]
: HelpTexts.HelpTextsDict[HelpTextEnum.PlayVideo]);
}
@@ -346,6 +339,7 @@ public partial class MainWindow
// }
private async void OpenFolderItemClick(object sender, RoutedEventArgs e) => await OpenFolder();
private async void OpenFolderButtonClick(object sender, RoutedEventArgs e) => await OpenFolder();
private async Task OpenFolder()
{
var dlg = new CommonOpenFileDialog
@@ -365,6 +359,7 @@ public partial class MainWindow
ReloadFiles();
}
private void TbFilter_OnTextChanged(object sender, TextChangedEventArgs e)
{
FilteredMediaFiles = new ObservableCollection<MediaFileInfo>(AllMediaFiles.Where(x => x.Name.ToLower().Contains(TbFilter.Text.ToLower())).ToList());
@@ -387,15 +382,22 @@ public partial class MainWindow
private void StopClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Stop));
private void PreviousFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.PreviousFrame));
private void NextFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.NextFrame));
private void NextFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.NextFrame));
private void SaveAnnotationsClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.SaveAnnotations));
private void RemoveSelectedClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.RemoveSelectedAnns));
private void RemoveAllClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.RemoveAllAnns));
private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOffVolume));
private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOnVolume));
private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOffVolume));
private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOnVolume));
private async void AutoDetect(object sender, RoutedEventArgs e)
{
if (LvFiles.SelectedItem == null)
return;
await _mediator.Send(new AIDetectEvent());
}
private void OpenHelpWindowClick(object sender, RoutedEventArgs e)
{
_helpWindow.Show();
@@ -410,7 +412,7 @@ public partial class MainWindow
var dgRow = ItemsControl.ContainerFromElement((DataGrid)sender, (args.OriginalSource as DependencyObject)!) as DataGridRow;
var res = (AnnotationResult)dgRow!.Item;
_mediaPlayer.SetPause(true);
_mediaPlayer.Time = (long)res.Time.TotalMilliseconds;// + 250;
_mediaPlayer.Time = (long)res.Time.TotalMilliseconds; // + 250;
ShowTimeAnnotations(res.Time);
};
}