1- using System ;
1+ using MORT . Logger ;
2+ using System ;
23using System . Collections . Generic ;
34using System . Diagnostics ;
45using System . Drawing ;
89using System . Runtime . InteropServices ;
910using System . Text ;
1011using System . Threading . Tasks ;
12+ using System . Windows . Interop ;
13+ using static System . Windows . Forms . VisualStyles . VisualStyleElement . ListView ;
1114
1215namespace MORT . OcrApi . OneOcr
1316{
@@ -51,6 +54,7 @@ public class OneOcr
5154
5255 public void CopyDll ( string path )
5356 {
57+ Logger . Logger . AddLog ( "dll 복사중" ) ;
5458 Directory . CreateDirectory ( OneOcrPath ) ;
5559 //File.Delete(Path.Combine(OneOcrPath, ErrorPath));
5660 try
@@ -61,6 +65,7 @@ public void CopyDll(string path)
6165 }
6266 catch ( Exception ex )
6367 {
68+ Logger . Logger . AddLog ( "복사 실패" ) ;
6469 Console . WriteLine ( ex . Message ) ;
6570 }
6671 }
@@ -74,8 +79,10 @@ public async ValueTask InitalizeAsync()
7479
7580 try
7681 {
82+ Logger . Logger . AddLog ( "Snipping OCR 초기화 시도" ) ;
7783 if ( ! File . Exists ( Path . Combine ( OneOcrPath , OneOcrDll ) ) )
7884 {
85+ Logger . Logger . AddLog ( "dll 존재하지 않음 - 복사 시도" ) ;
7986 var scketch = await GetInstallLocation ( "Microsoft.ScreenSketch" ) . ConfigureAwait ( false ) ;
8087 if ( ! string . IsNullOrEmpty ( scketch ) )
8188 {
@@ -87,6 +94,7 @@ public async ValueTask InitalizeAsync()
8794 }
8895 else
8996 {
97+ Logger . Logger . AddLog ( "없어서 Phots에서 복사 시도" ) ;
9098 var photo = await GetInstallLocation ( "Microsoft.Windows.Photos" ) . ConfigureAwait ( false ) ;
9199 if ( File . Exists ( Path . Combine ( photo , "oneocr.dll" ) ) )
92100 {
@@ -110,33 +118,41 @@ public async ValueTask InitalizeAsync()
110118 var ctx = Context ;
111119 Console . WriteLine ( $ "OneOcr DLL Path: { modelPath } ") ;
112120
121+ Logger . Logger . AddLog ( "OCR 생성중" ) ;
113122 // Create OCR pipeline — 여러 방식으로 시도하는 안전한 폴백 사용
114123 if ( ! TryCreateOcrPipelineWithFallback ( modelPath , key , ctx , out long pipeline , out var pipelineDetails ) )
115124 {
125+
116126 var msg = $ "CreateOcrPipeline failed. modelPath={ modelPath } , dllPath={ OneOcrPath } \n Details: { pipelineDetails } ";
117127 Console . Error . WriteLine ( msg ) ;
118128 Debug . WriteLine ( msg ) ;
129+
130+ Logger . Logger . AddLog ( $ "생성 실패 { msg } ") ;
119131 System . Windows . Forms . MessageBox . Show ( $ "oneocr 초기화 실패:\n { pipelineDetails } ") ;
120132 return ;
121133 }
122134
123135 // Set process options
136+ Logger . Logger . AddLog ( $ "옵션 생성중") ;
124137 long res = NativeMethods . CreateOcrProcessOptions ( out long opt ) ;
125138 if ( res != 0 )
126139 {
127140 var msg = $ "CreateOcrProcessOptions failed. res={ res } ";
128141 Console . Error . WriteLine ( msg ) ;
129142 Debug . WriteLine ( msg ) ;
143+ Logger . Logger . AddLog ( $ "옵션 실패 { msg } ") ;
130144 // try to cleanup pipeline if needed (if native provides)
131145 return ;
132146 }
133147
148+ Logger . Logger . AddLog ( $ "최대수 지정") ;
134149 res = NativeMethods . OcrProcessOptionsSetMaxRecognitionLineCount ( opt , 1000 ) ;
135150 if ( res != 0 )
136151 {
137152 var msg = $ "OcrProcessOptionsSetMaxRecognitionLineCount failed. res={ res } ";
138153 Console . Error . WriteLine ( msg ) ;
139154 Debug . WriteLine ( msg ) ;
155+ Logger . Logger . AddLog ( $ "실패 { msg } ") ;
140156 return ;
141157 }
142158
@@ -163,6 +179,7 @@ private bool TryCreateOcrPipelineWithFallback(string modelPath, string key, long
163179 catch ( Exception ex )
164180 {
165181 details += $ "Utf8 ex: { ex . GetType ( ) . Name } :{ ex . Message } ";
182+ Logger . Logger . AddLog ( $ "UTF 8 실패 { details } ") ;
166183 }
167184
168185 // 2) UTF-16 오버로드 시도 (추가한 CreateOcrPipeline_Utf16)
@@ -174,7 +191,9 @@ private bool TryCreateOcrPipelineWithFallback(string modelPath, string key, long
174191 }
175192 catch ( Exception ex )
176193 {
194+
177195 details += " | Utf16 ex: " + ex . GetType ( ) . Name + ":" + ex . Message ;
196+ Logger . Logger . AddLog ( $ "UTF 16 실패 { details } ") ;
178197 }
179198
180199 // 3) 우회: 모델 파일을 ASCII-only 임시 경로로 복사해 재시도
@@ -196,6 +215,7 @@ private bool TryCreateOcrPipelineWithFallback(string modelPath, string key, long
196215 catch ( Exception ex )
197216 {
198217 details += " | Copy->Utf8 ex: " + ex . GetType ( ) . Name + ":" + ex . Message ;
218+ Logger . Logger . AddLog ( $ "ascii 8 실패 { details } ") ;
199219 }
200220
201221 try
@@ -207,16 +227,19 @@ private bool TryCreateOcrPipelineWithFallback(string modelPath, string key, long
207227 catch ( Exception ex )
208228 {
209229 details += " | Copy->Utf16 ex: " + ex . GetType ( ) . Name + ":" + ex . Message ;
230+ Logger . Logger . AddLog ( $ "ascii 16 실패 { details } ") ;
210231 }
211232 }
212233 catch ( Exception ex )
213234 {
214235 details += " | Copy failed: " + ex . GetType ( ) . Name + ":" + ex . Message ;
236+ Logger . Logger . AddLog ( $ "복사 실패 { details } ") ;
215237 }
216238 }
217239 catch ( Exception ex )
218240 {
219241 details += " | Unexpected: " + ex . GetType ( ) . Name + ":" + ex . Message ;
242+ Logger . Logger . AddLog ( $ "알 수 없는 오류 { details } ") ;
220243 }
221244
222245 return false ;
@@ -255,21 +278,25 @@ private Line[] RunOcr(Img img)
255278 {
256279 // Run OCR pipeline
257280 long res = NativeMethods . RunOcrPipeline ( _pipeline , ref img , _opt , out long instance ) ;
281+ Logger . Logger . AddLog ( $ "ocr 시작") ;
258282 if ( res != 0 )
259283 {
260284 var msg = $ "RunOcrPipeline failed. res={ res } ";
285+ Logger . Logger . AddLog ( $ "시작 실패 { msg } ") ;
261286 Console . Error . WriteLine ( msg ) ;
262287 Debug . WriteLine ( msg ) ;
263- return null ;
288+ return new Line [ 0 ] ;
264289 }
265290
266291 // Get the number of recognized lines
267292 res = NativeMethods . GetOcrLineCount ( instance , out long lineCount ) ;
293+ Logger . Logger . AddLog ( $ "ocr line { lineCount } ") ;
268294 if ( res != 0 )
269295 {
270296 var msg = $ "GetOcrLineCount failed. res={ res } ";
271297 Console . Error . WriteLine ( msg ) ;
272298 Debug . WriteLine ( msg ) ;
299+ Logger . Logger . AddLog ( $ "line 실패 { msg } ") ;
273300 return null ;
274301 }
275302
@@ -335,19 +362,24 @@ private Line[] RunOcr(Img img)
335362 }
336363
337364 res = NativeMethods . GetOcrWordContent ( word , out IntPtr wordContentPtr ) ;
365+ Logger . Logger . AddLog ( $ "word count") ;
338366 if ( res != 0 || wordContentPtr == IntPtr . Zero )
339367 {
340368 Console . WriteLine ( $ "GetOcrWordContent failed for word { word } . res={ res } ") ;
369+
370+ Logger . Logger . AddLog ( $ "word count 실패 { word } / { res } ") ;
341371 continue ;
342372 }
343373
344374 // 마찬가지로 단어 텍스트도 managed string으로 변환
345375 string wordContent = PtrToManagedString ( wordContentPtr ) ;
346376
347377 res = NativeMethods . GetOcrWordBoundingBox ( word , out IntPtr wordBoundingBoxPtr ) ;
378+ Logger . Logger . AddLog ( $ "get ocr box") ;
348379 if ( res != 0 || wordBoundingBoxPtr == IntPtr . Zero )
349380 {
350381 Console . WriteLine ( $ "GetOcrWordBoundingBox failed for word { word } . res={ res } ") ;
382+ Logger . Logger . AddLog ( $ "ocr box 실패 { word } / { res } ") ;
351383 continue ;
352384 }
353385
@@ -377,20 +409,23 @@ private Line[] RunOcr(Img img)
377409 var msg = $ "DLL not found: { ex . Message } ";
378410 Console . Error . WriteLine ( msg ) ;
379411 Debug . WriteLine ( msg ) ;
412+ Logger . Logger . AddLog ( $ "dll not found 실패 { msg } ") ;
380413 throw ;
381414 }
382415 catch ( BadImageFormatException ex )
383416 {
384417 var msg = $ "BadImageFormat (bitness mismatch?): { ex . Message } ";
385418 Console . Error . WriteLine ( msg ) ;
386419 Debug . WriteLine ( msg ) ;
420+ Logger . Logger . AddLog ( $ "bad image 실패 { msg } ") ;
387421 throw ;
388422 }
389423 catch ( Exception ex )
390424 {
391425 var msg = $ "RunOcr unexpected error: { ex . Message } \n { ex . StackTrace } ";
392426 Console . Error . WriteLine ( msg ) ;
393427 Debug . WriteLine ( msg ) ;
428+ Logger . Logger . AddLog ( $ "unexpted 실패 { msg } ") ;
394429 throw ;
395430 }
396431 }
@@ -512,6 +547,7 @@ public async ValueTask<Line[]> ConvertToTextAsync(byte[] byteData, int channel,
512547 Bitmap bitmap = null ;
513548 BitmapData bitmapData = null ;
514549
550+
515551 try
516552 {
517553 // byte 배열로부터 Bitmap과 LockBits된 BitmapData 생성
0 commit comments