mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:46:30 +00:00
add dummy dlls for show wrong pass caption
add image processing
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Azaion.Common;
|
||||
@@ -513,10 +514,6 @@ public partial class Annotator
|
||||
_mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Play));
|
||||
_mediaPlayer.SetPause(true);
|
||||
|
||||
var mediaInfo = (MediaFileInfo)LvFiles.SelectedItem;
|
||||
_formState.CurrentMedia = mediaInfo;
|
||||
var path = mediaInfo.Path;
|
||||
|
||||
var manualCancellationSource = new CancellationTokenSource();
|
||||
var token = manualCancellationSource.Token;
|
||||
|
||||
@@ -534,40 +531,81 @@ public partial class Annotator
|
||||
_autoDetectDialog.Top = Height - _autoDetectDialog.Height - 80;
|
||||
_autoDetectDialog.Left = 5;
|
||||
|
||||
_autoDetectDialog.Log("Ініціалізація AI...");
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
Dispatcher.Invoke(() => _autoDetectDialog.Log("Ініціалізація AI..."));
|
||||
var prevSeekTime = 0.0;
|
||||
|
||||
await foreach (var timeframe in _vlcFrameExtractor.ExtractFrames(path, token))
|
||||
MediaFileInfo mediaInfo = null!;
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var detections = await _aiDetector.Detect(timeframe.Stream, token);
|
||||
if (timeframe.Time.TotalSeconds > prevSeekTime + 1)
|
||||
{
|
||||
Dispatcher.Invoke(() => SeekTo(timeframe.Time));
|
||||
prevSeekTime = timeframe.Time.TotalSeconds;
|
||||
}
|
||||
mediaInfo = (MediaFileInfo)LvFiles.SelectedItem;
|
||||
});
|
||||
|
||||
if (!IsValidDetection(timeframe.Time, detections))
|
||||
continue;
|
||||
|
||||
await ProcessDetection(timeframe, detections, token);
|
||||
}
|
||||
catch (Exception ex)
|
||||
while (mediaInfo != null)
|
||||
{
|
||||
_formState.CurrentMedia = mediaInfo;
|
||||
if (mediaInfo.MediaType == MediaTypes.Image)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
await manualCancellationSource.CancelAsync();
|
||||
await DetectImage(mediaInfo, manualCancellationSource, token);
|
||||
}
|
||||
else
|
||||
await DetectVideo(mediaInfo, manualCancellationSource, token);
|
||||
|
||||
mediaInfo = Dispatcher.Invoke(() =>
|
||||
{
|
||||
LvFiles.SelectedIndex += 1;
|
||||
return (MediaFileInfo)LvFiles.SelectedItem;
|
||||
});
|
||||
}
|
||||
Dispatcher.Invoke(() => _autoDetectDialog.Close());
|
||||
}, token);
|
||||
_autoDetectDialog.ShowDialog();
|
||||
|
||||
_autoDetectDialog.ShowDialog();
|
||||
Dispatcher.Invoke(() => Editor.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)));
|
||||
}
|
||||
|
||||
private async Task DetectImage(MediaFileInfo mediaInfo, CancellationTokenSource manualCancellationSource, CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = new FileStream(mediaInfo.Path, FileMode.Open);
|
||||
var detections = await _aiDetector.Detect(stream, token);
|
||||
await ProcessDetection((TimeSpan.FromMilliseconds(0), stream), detections, token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, e.Message);
|
||||
await manualCancellationSource.CancelAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DetectVideo(MediaFileInfo mediaInfo, CancellationTokenSource manualCancellationSource, CancellationToken token)
|
||||
{
|
||||
var prevSeekTime = 0.0;
|
||||
await foreach (var timeframe in _vlcFrameExtractor.ExtractFrames(mediaInfo.Path, token))
|
||||
{
|
||||
try
|
||||
{
|
||||
var detections = await _aiDetector.Detect(timeframe.Stream, token);
|
||||
if (timeframe.Time.TotalSeconds > prevSeekTime + 1)
|
||||
{
|
||||
Dispatcher.Invoke(() => SeekTo(timeframe.Time));
|
||||
prevSeekTime = timeframe.Time.TotalSeconds;
|
||||
}
|
||||
|
||||
if (!IsValidDetection(timeframe.Time, detections))
|
||||
continue;
|
||||
|
||||
await ProcessDetection(timeframe, detections, token);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
await manualCancellationSource.CancelAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsValidDetection(TimeSpan time, List<Detection> detections)
|
||||
{
|
||||
// No AI detection, forbid
|
||||
|
||||
Reference in New Issue
Block a user