mirror of
https://github.com/unclshura/splitter.git
synced 2026-09-21 15:43:39 +00:00
Compare commits
3 Commits
593d845b54
...
a971ceff2c
| Author | SHA1 | Date | |
|---|---|---|---|
| a971ceff2c | |||
| 7b40095ccd | |||
| b4e18963dd |
9
Directory.Build.props
Normal file
9
Directory.Build.props
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
22
Directory.Packages.props
Normal file
22
Directory.Packages.props
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageVersion Include="Avalonia" Version="12.1.2" />
|
||||||
|
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="12.1.2" />
|
||||||
|
<PackageVersion Include="Avalonia.Desktop" Version="12.1.2" />
|
||||||
|
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.2" />
|
||||||
|
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.2" />
|
||||||
|
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3" />
|
||||||
|
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
|
||||||
|
<PackageVersion Include="FFmpeg.AutoGen" Version="9.0.1.1" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.12" />
|
||||||
|
<PackageVersion Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
|
||||||
|
<PackageVersion Include="Onnxify" Version="0.3.11" />
|
||||||
|
<PackageVersion Include="OpenCvSharp4" Version="4.13.0.20260627" />
|
||||||
|
<PackageVersion Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260627" />
|
||||||
|
<PackageVersion Include="Spectre.Console" Version="0.57.2" />
|
||||||
|
<PackageVersion Include="UltraFaceDotNet" Version="1.0.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@ -1,62 +1,42 @@
|
|||||||
namespace Splitter_UI.Services;
|
using System.Buffers;
|
||||||
|
|
||||||
|
namespace Splitter_UI.Services;
|
||||||
|
|
||||||
public sealed class BufferPool : IBufferPool
|
public sealed class BufferPool : IBufferPool
|
||||||
{
|
{
|
||||||
|
public sealed class Entry : IDisposable
|
||||||
public sealed class Entry
|
|
||||||
{
|
{
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
public readonly int Width;
|
public readonly int Width;
|
||||||
public readonly int Height;
|
public readonly int Height;
|
||||||
public readonly byte[] Bgr;
|
|
||||||
public readonly byte[] Bgra;
|
|
||||||
|
|
||||||
public Entry(int w, int h)
|
public byte[] Bgr;
|
||||||
|
public byte[] Bgra;
|
||||||
|
|
||||||
|
internal Entry(int w, int h)
|
||||||
{
|
{
|
||||||
Width = w;
|
Width = w;
|
||||||
Height = h;
|
Height = h;
|
||||||
Bgr = new byte[w * h * 3];
|
|
||||||
Bgra = new byte[w * h * 4];
|
Bgr = ArrayPool<byte>.Shared.Rent(w * h * 3);
|
||||||
|
Bgra = ArrayPool<byte>.Shared.Rent(w * h * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public string ToString() => $"Entry({Width}x{Height})";
|
public void Dispose()
|
||||||
}
|
{
|
||||||
|
if (_disposed) return;
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
private readonly Dictionary<(int w, int h), LinkedListNode<Entry>> _map;
|
ArrayPool<byte>.Shared.Return(Bgr);
|
||||||
private readonly LinkedList<Entry> _lru;
|
ArrayPool<byte>.Shared.Return(Bgra);
|
||||||
private readonly int _capacity;
|
}
|
||||||
private readonly Lock _lock = new();
|
|
||||||
|
|
||||||
public BufferPool()
|
public override string ToString() => $"Entry({Width}x{Height})";
|
||||||
{
|
|
||||||
_capacity = 8;
|
|
||||||
_map = new Dictionary<(int w, int h), LinkedListNode<Entry>>(_capacity);
|
|
||||||
_lru = new LinkedList<Entry>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry Get(int w, int h)
|
public Entry Get(int w, int h)
|
||||||
{
|
{
|
||||||
var key = (w, h);
|
return new Entry(w, h);
|
||||||
|
|
||||||
if (_map.TryGetValue(key, out var node))
|
|
||||||
{
|
|
||||||
_lru.Remove(node);
|
|
||||||
_lru.AddLast(node);
|
|
||||||
return node.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
var created = new Entry(w, h);
|
|
||||||
var newNode = new LinkedListNode<Entry>(created);
|
|
||||||
|
|
||||||
_lru.AddLast(newNode);
|
|
||||||
_map[key] = newNode;
|
|
||||||
|
|
||||||
if (_lru.Count > _capacity)
|
|
||||||
{
|
|
||||||
var first = _lru.First!;
|
|
||||||
_lru.RemoveFirst();
|
|
||||||
_map.Remove((first.Value.Width, first.Value.Height));
|
|
||||||
}
|
|
||||||
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
|
|||||||
|
|
||||||
lock (_sync)
|
lock (_sync)
|
||||||
{
|
{
|
||||||
var entry = _pool.Get(w, h);
|
using var entry = _pool.Get(w, h);
|
||||||
|
|
||||||
var src = mat;
|
var src = mat;
|
||||||
if (!src.IsContinuous())
|
if (!src.IsContinuous())
|
||||||
@ -65,7 +65,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
|
|||||||
|
|
||||||
public Bitmap Convert(byte[] bgr, int width, int height, Bitmap? existing = null)
|
public Bitmap Convert(byte[] bgr, int width, int height, Bitmap? existing = null)
|
||||||
{
|
{
|
||||||
var entry = _pool.Get(width, height);
|
using var entry = _pool.Get(width, height);
|
||||||
ConvertBgrToBgra(bgr, entry.Bgra, width, height);
|
ConvertBgrToBgra(bgr, entry.Bgra, width, height);
|
||||||
|
|
||||||
if (existing is WriteableBitmap wb &&
|
if (existing is WriteableBitmap wb &&
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public sealed class ThumbnailService : IThumbnailService
|
|||||||
height ??= ThumbHeight;
|
height ??= ThumbHeight;
|
||||||
skip ??= TimeSpan.Zero;
|
skip ??= TimeSpan.Zero;
|
||||||
|
|
||||||
var entry = _pool.Get(width.Value, height.Value);
|
using var entry = _pool.Get(width.Value, height.Value);
|
||||||
|
|
||||||
var ok = await DecodeFrameAsync(
|
var ok = await DecodeFrameAsync(
|
||||||
entry.Bgr,
|
entry.Bgr,
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<LangVersion>latest</LangVersion>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
@ -18,17 +14,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="12.0.4" />
|
<PackageReference Include="Avalonia" />
|
||||||
<PackageReference Include="Avalonia.Controls.DataGrid" Version="12.0.0" />
|
<PackageReference Include="Avalonia.Controls.DataGrid" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="12.0.4" />
|
<PackageReference Include="Avalonia.Desktop" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.4" />
|
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.4" />
|
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||||
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3">
|
<PackageReference Include="AvaloniaUI.DiagnosticsSupport">
|
||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
|
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -47,6 +47,7 @@ public sealed class CameraController
|
|||||||
_cropHeight = cropHeight;
|
_cropHeight = cropHeight;
|
||||||
_kalman = kalman;
|
_kalman = kalman;
|
||||||
_cmd = cmd;
|
_cmd = cmd;
|
||||||
|
DefaultCenter = new Point2f(videoWidth * _cmd.GravitateTo.X, videoHeight * _cmd.GravitateTo.Y);
|
||||||
_cameraCenter = DefaultCenter;
|
_cameraCenter = DefaultCenter;
|
||||||
_state = TrackState.Tracking;
|
_state = TrackState.Tracking;
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public sealed class CameraController
|
|||||||
_kalman.Reset(_cameraCenter);
|
_kalman.Reset(_cameraCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point2f DefaultCenter => _cmd.GravitateTo;
|
private Point2f DefaultCenter { get; set; }
|
||||||
|
|
||||||
public int LostFrames => _lostFrames;
|
public int LostFrames => _lostFrames;
|
||||||
public Point2f CameraCenter => _cameraCenter;
|
public Point2f CameraCenter => _cameraCenter;
|
||||||
@ -148,7 +149,7 @@ public sealed class CameraController
|
|||||||
smoothedCenter = _kalman.Update(objectCenter);
|
smoothedCenter = _kalman.Update(objectCenter);
|
||||||
|
|
||||||
var driftEasing = 0.01f;
|
var driftEasing = 0.01f;
|
||||||
var fallbackCenter = new Point2f(_videoWidth / 2f, _videoHeight / 2f);
|
var fallbackCenter = DefaultCenter;
|
||||||
|
|
||||||
_cameraCenter = new Point2f(
|
_cameraCenter = new Point2f(
|
||||||
_cameraCenter.X + (fallbackCenter.X - _cameraCenter.X) * driftEasing,
|
_cameraCenter.X + (fallbackCenter.X - _cameraCenter.X) * driftEasing,
|
||||||
|
|||||||
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<LangVersion>latest</LangVersion>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
@ -57,13 +53,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FFmpeg.AutoGen" Version="8.1.0" />
|
<PackageReference Include="FFmpeg.AutoGen" />
|
||||||
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
|
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" />
|
||||||
<PackageReference Include="Onnxify" Version="0.3.4" />
|
<PackageReference Include="Onnxify" />
|
||||||
<PackageReference Include="OpenCvSharp4" Version="4.13.0.20260602" />
|
<PackageReference Include="OpenCvSharp4" />
|
||||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260602" />
|
<PackageReference Include="OpenCvSharp4.runtime.win" />
|
||||||
<PackageReference Include="Spectre.Console" Version="0.57.0" />
|
<PackageReference Include="Spectre.Console" />
|
||||||
<PackageReference Include="UltraFaceDotNet" Version="1.0.0.2" />
|
<PackageReference Include="UltraFaceDotNet" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user