@@ -21,7 +21,7 @@ public sealed class OneOcr : IOcrModule, IDisposable
2121{
2222 const string apiKey = "kj)TGtrK>f]b[Piow.gU+nC@s\" \" \" \" \" \" 4" ;
2323 const int maxLineCount = 1000 ;
24- private readonly FastTextDetector fastText ;
24+ private readonly FastTextDetector ? fastText ;
2525 private readonly ILogger < OneOcr > logger ;
2626 private readonly string source ;
2727 private readonly HashSet < string > targets ;
@@ -57,9 +57,16 @@ private static nint Context_ResolvingUnmanagedDll(Assembly assembly, string arg2
5757
5858 public OneOcr ( ILogger < OneOcr > logger , IOptionsSnapshot < LanguageOptions > langOptions , IOptionsSnapshot < BasicOcrParam > ocrParam )
5959 {
60- this . fastText = new FastTextDetector ( ) ;
61- this . fastText . LoadDefaultModel ( ) ;
6260 this . logger = logger ;
61+ try
62+ {
63+ this . fastText = new FastTextDetector ( ) ;
64+ this . fastText . LoadDefaultModel ( ) ;
65+ }
66+ catch ( DllNotFoundException )
67+ {
68+ this . logger . LogError ( "FastTextのDLLが見つからないため、言語判定処理は利用出来ません" ) ;
69+ }
6370 this . source = langOptions . Value . Source ;
6471 this . targets = [ langOptions . Value . Target [ ..2 ] ] ;
6572 if ( this . targets . Overlaps ( [ "ja" , "zh" ] ) && this . source [ ..2 ] is not "ja" and not "zh" )
@@ -119,7 +126,7 @@ public OneOcr(ILogger<OneOcr> logger, IOptionsSnapshot<LanguageOptions> langOpti
119126
120127 public void Dispose ( )
121128 {
122- this . fastText . Dispose ( ) ;
129+ this . fastText ? . Dispose ( ) ;
123130 }
124131
125132 public async ValueTask < IEnumerable < TextRect > > RecognizeAsync ( SoftwareBitmap bitmap )
@@ -153,7 +160,7 @@ public async ValueTask<IEnumerable<TextRect>> RecognizeAsync(SoftwareBitmap bitm
153160 }
154161
155162 private bool IsTargetLangText ( string text )
156- => this . fastText . Predict ( text , 3 , 0.7f ) . Any ( p => this . targets . Contains ( p . Label [ ( p . Label . LastIndexOf ( '_' ) + 1 ) ..] ) ) ;
163+ => this . fastText ? . Predict ( text , 3 , 0.7f ) . Any ( p => this . targets . Contains ( p . Label [ ( p . Label . LastIndexOf ( '_' ) + 1 ) ..] ) ) ?? false ;
157164
158165 private unsafe IEnumerable < TextRect > Recognize ( SoftwareBitmap bitmap )
159166 {
0 commit comments