Add support for legacy DNN enums in NumberRecognitionEngine and update backend usage
All checks were successful
Build And Publish AIFotoONLUS.Core / build (push) Successful in 1m31s
Build And Publish AIFotoONLUS.Core / publish (push) Successful in 1m10s

This commit is contained in:
Maddo 2026-11-30 19:43:10 +01:00
commit 8170e252e6
2 changed files with 16 additions and 5 deletions

View file

@ -25,6 +25,9 @@
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Windows'))"> <PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<UseCudaOpenCvRuntime>true</UseCudaOpenCvRuntime> <UseCudaOpenCvRuntime>true</UseCudaOpenCvRuntime>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(UseCudaOpenCvRuntime)' == 'true'">
<DefineConstants>$(DefineConstants);OPENCVSHARP_LEGACY_DNN_ENUMS</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenCvSharp4" Version="4.5.0.20201013" Condition="'$(UseCudaOpenCvRuntime)' == 'true'" /> <PackageReference Include="OpenCvSharp4" Version="4.5.0.20201013" Condition="'$(UseCudaOpenCvRuntime)' == 'true'" />
<PackageReference Include="OpenCvSharp4.runtime.win.cuda" Version="4.5.0.20201013" Condition="'$(UseCudaOpenCvRuntime)' == 'true'" /> <PackageReference Include="OpenCvSharp4.runtime.win.cuda" Version="4.5.0.20201013" Condition="'$(UseCudaOpenCvRuntime)' == 'true'" />

View file

@ -9,6 +9,14 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#if OPENCVSHARP_LEGACY_DNN_ENUMS
using DnnBackend = OpenCvSharp.Dnn.Net.Backend;
using DnnTarget = OpenCvSharp.Dnn.Net.Target;
#else
using DnnBackend = OpenCvSharp.Dnn.Backend;
using DnnTarget = OpenCvSharp.Dnn.Target;
#endif
namespace AIFotoONLUS.Core namespace AIFotoONLUS.Core
{ {
/// <summary> /// <summary>
@ -167,20 +175,20 @@ namespace AIFotoONLUS.Core
{ {
if (useGpu) if (useGpu)
{ {
net.SetPreferableBackend(Net.Backend.CUDA); net.SetPreferableBackend(DnnBackend.CUDA);
try try
{ {
net.SetPreferableTarget(Net.Target.CUDA_FP16); net.SetPreferableTarget(DnnTarget.CUDA_FP16);
} }
catch catch
{ {
net.SetPreferableTarget(Net.Target.CUDA); net.SetPreferableTarget(DnnTarget.CUDA);
} }
return; return;
} }
net.SetPreferableBackend(Net.Backend.OPENCV); net.SetPreferableBackend(DnnBackend.OPENCV);
net.SetPreferableTarget(Net.Target.CPU); net.SetPreferableTarget(DnnTarget.CPU);
} }
private void EnsureGpuRuntimeValidated() private void EnsureGpuRuntimeValidated()