@@ -5,13 +5,12 @@ namespace tbm.ImagePipeline.Ocr;
5
5
public sealed partial class TesseractRecognizer ( IConfiguration config , string script ) : IDisposable
6
6
{
7
7
private readonly IConfigurationSection _config = config . GetSection ( "OcrConsumer:Tesseract" ) ;
8
- private Lazy < OCRTesseract > ? _tesseractInstanceHorizontal ;
9
- private Lazy < OCRTesseract > ? _tesseractInstanceVertical ;
10
8
11
9
public delegate TesseractRecognizer New ( string script ) ;
12
10
13
11
[ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ]
14
- private Lazy < OCRTesseract > TesseractInstanceHorizontal => _tesseractInstanceHorizontal ??= new ( script switch
12
+ [ field: AllowNull , MaybeNull ]
13
+ private Lazy < OCRTesseract > TesseractInstanceHorizontal => field ??= new ( script switch
15
14
{ // https://en.wikipedia.org/wiki/Template:ISO_15924_script_codes_and_related_Unicode_data
16
15
"Hans" => CreateTesseract ( "best/chi_sim+best/eng" ) ,
17
16
"Hant" => CreateTesseract ( "best/chi_tra+best/eng" ) ,
@@ -21,7 +20,8 @@ public sealed partial class TesseractRecognizer(IConfiguration config, string sc
21
20
} ) ;
22
21
23
22
[ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ]
24
- private Lazy < OCRTesseract > TesseractInstanceVertical => _tesseractInstanceVertical ??= new ( script switch
23
+ [ field: AllowNull , MaybeNull ]
24
+ private Lazy < OCRTesseract > TesseractInstanceVertical => field ??= new ( script switch
25
25
{
26
26
"Hans" => CreateTesseract ( "best/chi_sim_vert" , isVertical : true ) ,
27
27
"Hant" => CreateTesseract ( "best/chi_tra_vert" , isVertical : true ) ,
@@ -43,7 +43,7 @@ public void Dispose()
43
43
// https://github.com/shimat/opencvsharp/issues/873#issuecomment-1458868153
44
44
// https://pyimagesearch.com/2021/11/15/tesseract-page-segmentation-modes-psms-explained-how-to-improve-your-ocr-accuracy/
45
45
private OCRTesseract CreateTesseract ( string scripts , bool isVertical = false ) =>
46
- OCRTesseract . Create ( _config . GetValue ( "DataPath" , "" ) ?? "" ,
46
+ OCRTesseract . Create ( _config . GetValue ( "DataPath" , "" ) ,
47
47
scripts , charWhitelist : "" , oem : 1 , psmode : isVertical ? 5 : 7 ) ;
48
48
}
49
49
public sealed partial class TesseractRecognizer
0 commit comments