add dummy dlls for show wrong pass caption

add image processing
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-01 00:46:47 +02:00
parent 362ba439ea
commit 0b38d9b24c
25 changed files with 398 additions and 30 deletions
+63 -25
View File
@@ -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
+12 -2
View File
@@ -23,8 +23,18 @@ public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : I
var assemblyName = resourceName.Split(',').First();
if (EncryptedResources.Contains(assemblyName))
{
var stream = Load($"{assemblyName}.dll").GetAwaiter().GetResult();
return Assembly.Load(stream.ToArray());
try
{
var stream = Load($"{assemblyName}.dll").GetAwaiter().GetResult();
return Assembly.Load(stream.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e);
var currentLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var dllPath = Path.Combine(currentLocation, "dummy", $"{assemblyName}.dll");
return Assembly.LoadFile(dllPath);
}
}
var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies()
+1 -2
View File
@@ -74,14 +74,13 @@
BorderBrush="DimGray"
BorderThickness="0,0,0,1"
HorizontalAlignment="Left"
Text="admin@azaion.com"/>
/>
<TextBlock Text="Пароль"
Grid.Row="2"
Margin="0, 20, 0, 5"
HorizontalAlignment="Left"/>
<PasswordBox Grid.Row="3"
Name="TbPassword"
Password="Az@1on1000Odm$n"
FontSize="16"
Background="DarkGray"
BorderBrush="DimGray"
+22
View File
@@ -12,6 +12,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Dataset", "Azaion.Da
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Launcher", "Azaion.Launcher\Azaion.Launcher.csproj", "{00CC9AFE-2952-4943-BCBA-976AE03DE841}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dummy", "Dummy", "{C307BE2E-FFCC-4BD7-AD89-C82D40B65D03}"
ProjectSection(SolutionItems) = preProject
Dummy\Azaion.Annotator.dll = Dummy\Azaion.Annotator.dll
Dummy\Azaion.Dataset.dll = Dummy\Azaion.Dataset.dll
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Annotator", "Dummy\Azaion.Annotator\Azaion.Annotator.csproj", "{32C4747F-F700-44FD-B4ED-21B4A66B5FAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Dataset", "Dummy\Azaion.Dataset\Azaion.Dataset.csproj", "{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -42,5 +52,17 @@ Global
{00CC9AFE-2952-4943-BCBA-976AE03DE841}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00CC9AFE-2952-4943-BCBA-976AE03DE841}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00CC9AFE-2952-4943-BCBA-976AE03DE841}.Release|Any CPU.Build.0 = Release|Any CPU
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB}.Release|Any CPU.Build.0 = Release|Any CPU
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03}
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03}
EndGlobalSection
EndGlobal
-1
View File
@@ -108,7 +108,6 @@ public partial class App
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
services.AddSingleton<Annotator.Annotator>();
services.AddSingleton<DatasetExplorer>();
services.AddSingleton<HelpWindow>();
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
<Window x:Class="Azaion.Annotator.Annotator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Azaion Annotator" Height="800" Width="1100"
WindowState="Maximized"
>
<TextBlock Padding="20 80"
Background="Black"
Foreground="Brown"
TextWrapping="Wrap"
FontSize="32"
TextAlignment="Center">
Будь ласка перевірте правильність email чи паролю! <LineBreak />
Також зауважте, що запуск можливий лише з одного конкретного компьютера, копіювання заборонене! <LineBreak/> <LineBreak/>
Для подальшого вирішення проблеми ви моежете зв'язатися з нами: hi@azaion.com
<LineBreak /><LineBreak /><LineBreak />
Please check your email or password! <LineBreak />
The program is restricted to start only from particular hardware, copying is forbidden! <LineBreak/> <LineBreak/>
For the further guidance, please feel free to contact us: hi@azaion.com
</TextBlock>
</Window>
+9
View File
@@ -0,0 +1,9 @@
namespace Azaion.Annotator;
public partial class Annotator
{
public Annotator()
{
InitializeComponent();
}
}
@@ -0,0 +1,3 @@
namespace Azaion.Annotator;
public class AnnotatorEventHandler;
+54
View File
@@ -0,0 +1,54 @@
using Azaion.Common.DTO;
namespace Azaion.Annotator;
public class AnnotatorModule : IAzaionModule
{
public string Name => "Анотатор";
public string SvgIcon =>
@"<?xml version=""1.0"" encoding=""utf-8""?>
<!-- Generator: Adobe Illustrator 28.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version=""1.1"" id=""Layer_1"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"" x=""0px"" y=""0px""
viewBox=""0 0 800 800"" style=""enable-background:new 0 0 800 800;"" xml:space=""preserve"">
<style type=""text/css"">
.st0{fill:#FFFFFF;}
.st1{opacity:0.75;fill:#006932;stroke:#000000;stroke-width:20;stroke-miterlimit:10;}
.st2{opacity:0.75;fill:#6C0A0B;stroke:#000000;stroke-width:20;stroke-miterlimit:10;}
.st3{fill:#FFFFFF;stroke:#434444;stroke-width:8;stroke-miterlimit:10;}
</style>
<g id=""SVGRepo_bgCarrier"">
</g>
<g id=""SVGRepo_tracerCarrier"">
</g>
<g id=""SVGRepo_iconCarrier"">
<g transform=""translate(1)"">
<g>
<polygon class=""st0"" points=""465.7,93.3 545.7,93.3 545.7,13.3 465.7,13.3""/>
</g>
</g>
</g>
<rect x=""43.3"" y=""53.3"" class=""st1"" width=""609.7"" height=""301""/>
<rect x=""443.2"" y=""400"" class=""st2"" width=""285.8"" height=""363""/>
<g>
<rect x=""19"" y=""325"" class=""st3"" width=""53"" height=""53""/>
<rect x=""17.5"" y=""166"" class=""st3"" width=""53"" height=""53""/>
<rect x=""17.5"" y=""27"" class=""st3"" width=""53"" height=""53""/>
<rect x=""325.5"" y=""329"" class=""st3"" width=""53"" height=""53""/>
<rect x=""624.5"" y=""325"" class=""st3"" width=""53"" height=""53""/>
<rect x=""626.5"" y=""168"" class=""st3"" width=""53"" height=""53""/>
<rect x=""626.5"" y=""27"" class=""st3"" width=""53"" height=""53""/>
<rect x=""323.5"" y=""27"" class=""st3"" width=""53"" height=""53""/>
<rect x=""419.8"" y=""377.3"" class=""st3"" width=""53"" height=""53""/>
<rect x=""698.7"" y=""378.3"" class=""st3"" width=""53"" height=""53""/>
<rect x=""418.5"" y=""733.2"" class=""st3"" width=""53"" height=""53""/>
<rect x=""698.7"" y=""736.5"" class=""st3"" width=""53"" height=""53""/>
<rect x=""415.8"" y=""555.7"" class=""st3"" width=""53"" height=""53""/>
<rect x=""701.2"" y=""551.7"" class=""st3"" width=""53"" height=""53""/>
</g>
</svg>";
public Type MainWindowType => typeof(Annotator);
public WindowEnum WindowEnum => WindowEnum.Annotator;
}
+10
View File
@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="libc.translation" Version="7.1.1" />
<PackageReference Include="LibVLCSharp" Version="3.9.1" />
<PackageReference Include="LibVLCSharp.WPF" Version="3.9.1" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RangeTree" Version="3.0.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.9" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
<PackageReference Include="WindowsAPICodePack" Version="7.0.4" />
<PackageReference Include="YoloV8.Gpu" Version="5.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Azaion.Common\Azaion.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="DTO\" />
<Folder Include="Extensions\" />
</ItemGroup>
</Project>
+3
View File
@@ -0,0 +1,3 @@
namespace Azaion.Annotator.DTO;
public class FormState;
@@ -0,0 +1,3 @@
namespace Azaion.Annotator.Extensions;
public class VLCFrameExtractor;
+11
View File
@@ -0,0 +1,11 @@
<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"
mc:Ignorable="d"
Height="700" Width="800"
ResizeMode="NoResize"
Topmost="True"
WindowStartupLocation="CenterScreen">
</Window>
@@ -0,0 +1,3 @@
namespace Azaion.Annotator;
public partial class HelpWindow;
+5
View File
@@ -0,0 +1,5 @@
namespace Azaion.Annotator;
public interface IAIDetector;
public class YOLODetector : IAIDetector;
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Page Update="DatasetExplorer.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="ScottPlot.WPF" Version="5.0.46" />
<PackageReference Include="VirtualizingWrapPanel" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Azaion.Common\Azaion.Common.csproj" />
</ItemGroup>
</Project>
+19
View File
@@ -0,0 +1,19 @@
using System.IO;
using System.Windows.Media.Imaging;
namespace Azaion.Dataset;
public static class BitmapExtensions
{
public static async Task<BitmapImage> OpenImage(this string imagePath)
{
var image = new BitmapImage();
await using var stream = File.OpenRead(imagePath);
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = stream;
image.EndInit();
image.Freeze();
return image;
}
}
+24
View File
@@ -0,0 +1,24 @@
<Window x:Class="Azaion.Dataset.DatasetExplorer"
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"
mc:Ignorable="d"
Title="Переглядач анотацій" Height="900" Width="1200"
WindowState="Maximized">
<TextBlock Padding="20 80"
Background="Black"
Foreground="Brown"
TextWrapping="Wrap"
FontSize="32"
TextAlignment="Center">
Будь ласка перевірте правильність email чи паролю! <LineBreak />
Також зауважте, що запуск можливий лише з одного конкретного компьютера, копіювання заборонене! <LineBreak/> <LineBreak/>
Для подальшого вирішення проблеми ви моежете зв'язатися з нами: hi@azaion.com
<LineBreak /><LineBreak /><LineBreak />
Please check your email or password! <LineBreak />
The program is restricted to start only from particular hardware, copying is forbidden! <LineBreak/> <LineBreak/>
For the further guidance, please feel free to contact us: hi@azaion.com
</TextBlock>
</Window>
@@ -0,0 +1,3 @@
namespace Azaion.Dataset;
public partial class DatasetExplorer;
@@ -0,0 +1,25 @@
using Azaion.Common.DTO;
namespace Azaion.Dataset;
public class DatasetExplorerModule : IAzaionModule
{
public string Name => "Переглядач";
public string SvgIcon =>
@"<?xml version=""1.0"" encoding=""utf-8""?>
<svg width=""800px"" height=""800px"" viewBox=""0 0 24 24"" xmlns=""http://www.w3.org/2000/svg"" fill=""none"" stroke=""#000000"" stroke-width=""1"" stroke-linecap=""round"" stroke-linejoin=""miter"">
<rect x=""2"" y=""2"" width=""8"" height=""8"" rx=""0"" fill=""#059cf7"" opacity=""0.8""></rect>
<rect x=""2"" y=""14"" width=""8"" height=""8"" rx=""0"" fill=""#059cf7"" opacity=""0.8""></rect>
<rect x=""14"" y=""2"" width=""8"" height=""8"" rx=""0"" fill=""#059cf7"" opacity=""0.8""></rect>
<rect x=""14"" y=""14"" width=""8"" height=""8"" rx=""0"" fill=""#059cf7"" opacity=""0.8""></rect>
<rect x=""2"" y=""2"" width=""8"" height=""8"" rx=""0""></rect>
<rect x=""2"" y=""14"" width=""8"" height=""8"" rx=""0""></rect>
<rect x=""14"" y=""2"" width=""8"" height=""8"" rx=""0""></rect>
<rect x=""14"" y=""14"" width=""8"" height=""8"" rx=""0""></rect>
</svg>";
public Type MainWindowType => typeof(DatasetExplorer);
public WindowEnum WindowEnum => WindowEnum.DatasetExplorer;
}
+24
View File
@@ -0,0 +1,24 @@
using System.Collections.Concurrent;
using System.Drawing;
using System.IO;
using Azaion.Annotator.Extensions;
using Azaion.Common;
using Azaion.Common.DTO;
using Azaion.Common.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Color = System.Drawing.Color;
using ParallelOptions = Azaion.Annotator.Extensions.ParallelOptions;
using Size = System.Windows.Size;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using Azaion.Common.DTO.Config;
namespace Azaion.Dataset;
public delegate void ThumbnailsUpdatedEventHandler(double thumbnailsPercentage);
public class GalleryManager : IGalleryManager;
public interface IGalleryManager;