@@ -28,6 +28,8 @@ public class OneOcr
2828 private long Context { get ; set ; }
2929
3030 private bool _initalized ;
31+ private long _pipeline ;
32+ private long _opt ;
3133
3234 // 안전한 DLL 검색 경로 등록 관련 필드
3335 private IntPtr _dllDirectoryCookie = IntPtr . Zero ;
@@ -84,6 +86,45 @@ public async ValueTask InitalizeAsync()
8486 }
8587 }
8688
89+ // Model key and path
90+ string key = "kj)TGtrK>f]b[Piow.gU+nC@s\" \" \" \" \" \" 4" ;
91+ string modelPath = Path . Combine ( OneOcrPath , OneOcrModel ) ;
92+ modelPath = Path . GetFullPath ( modelPath ) ;
93+
94+ var ctx = Context ;
95+ Console . WriteLine ( $ "OneOcr DLL Path: { modelPath } ") ;
96+ // Create OCR pipeline
97+ long res = NativeMethods . CreateOcrPipeline ( modelPath , key , ctx , out long pipeline ) ;
98+ if ( res != 0 )
99+ {
100+ var msg = $ "CreateOcrPipeline failed. res={ res } , modelPath={ modelPath } , dllPath={ OneOcrPath } ";
101+ Console . Error . WriteLine ( msg ) ;
102+ Debug . WriteLine ( msg ) ;
103+ return ;
104+ }
105+
106+ // Set process options
107+ res = NativeMethods . CreateOcrProcessOptions ( out long opt ) ;
108+ if ( res != 0 )
109+ {
110+ var msg = $ "CreateOcrProcessOptions failed. res={ res } ";
111+ Console . Error . WriteLine ( msg ) ;
112+ Debug . WriteLine ( msg ) ;
113+ // try to cleanup pipeline if needed (if native provides)
114+ return ;
115+ }
116+
117+ res = NativeMethods . OcrProcessOptionsSetMaxRecognitionLineCount ( opt , 1000 ) ;
118+ if ( res != 0 )
119+ {
120+ var msg = $ "OcrProcessOptionsSetMaxRecognitionLineCount failed. res={ res } ";
121+ Console . Error . WriteLine ( msg ) ;
122+ Debug . WriteLine ( msg ) ;
123+ return ;
124+ }
125+
126+ _pipeline = pipeline ;
127+ _opt = opt ;
87128 _initalized = true ;
88129 }
89130
@@ -111,52 +152,14 @@ public async ValueTask InitalizeAsync()
111152
112153 return path ;
113154 }
114- private bool _test ;
115- private long _pipeline ;
116- private long _opt ;
155+
156+
117157 private Line [ ] RunOcr ( Img img )
118158 {
119159 try
120160 {
121- // Model key and path
122- string key = "kj)TGtrK>f]b[Piow.gU+nC@s\" \" \" \" \" \" 4" ;
123- string modelPath = Path . Combine ( OneOcrPath , OneOcrModel ) ;
124- modelPath = Path . GetFullPath ( modelPath ) ;
125-
126- var ctx = Context ;
127- Console . WriteLine ( $ "OneOcr DLL Path: { modelPath } ") ;
128- // Create OCR pipeline
129- long res = NativeMethods . CreateOcrPipeline ( modelPath , key , ctx , out long pipeline ) ;
130- if ( res != 0 )
131- {
132- var msg = $ "CreateOcrPipeline failed. res={ res } , modelPath={ modelPath } , dllPath={ OneOcrPath } ";
133- Console . Error . WriteLine ( msg ) ;
134- Debug . WriteLine ( msg ) ;
135- return null ;
136- }
137-
138- // Set process options
139- res = NativeMethods . CreateOcrProcessOptions ( out long opt ) ;
140- if ( res != 0 )
141- {
142- var msg = $ "CreateOcrProcessOptions failed. res={ res } ";
143- Console . Error . WriteLine ( msg ) ;
144- Debug . WriteLine ( msg ) ;
145- // try to cleanup pipeline if needed (if native provides)
146- return null ;
147- }
148-
149- res = NativeMethods . OcrProcessOptionsSetMaxRecognitionLineCount ( opt , 1000 ) ;
150- if ( res != 0 )
151- {
152- var msg = $ "OcrProcessOptionsSetMaxRecognitionLineCount failed. res={ res } ";
153- Console . Error . WriteLine ( msg ) ;
154- Debug . WriteLine ( msg ) ;
155- return null ;
156- }
157-
158161 // Run OCR pipeline
159- res = NativeMethods . RunOcrPipeline ( pipeline , ref img , opt , out long instance ) ;
162+ long res = NativeMethods . RunOcrPipeline ( _pipeline , ref img , _opt , out long instance ) ;
160163 if ( res != 0 )
161164 {
162165 var msg = $ "RunOcrPipeline failed. res={ res } ";
0 commit comments