Skip to content

Commit a3a94cc

Browse files
committed
1.306 업데이트
Snipping Tool OCR - 활성화된 윈도우에서 캡쳐 사용시 간혈적으로 사용할 수 없음이 뜨는 문제 수정
1 parent 99ffb14 commit a3a94cc

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

MORT/OcrApi/OneOcr/OneOcr.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using MORT.Logger;
2+
using System;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Drawing;
@@ -8,6 +9,8 @@
89
using System.Runtime.InteropServices;
910
using System.Text;
1011
using System.Threading.Tasks;
12+
using System.Windows.Interop;
13+
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
1114

1215
namespace 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}\nDetails: {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 생성

MORT/Properties/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MORT/Properties/Settings.settings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<Profiles />
44
<Settings>
55
<Setting Name="MORT_VERSION" Type="System.String" Scope="Application">
6-
<Value Profile="(Default)">1.305V</Value>
6+
<Value Profile="(Default)">1.306V</Value>
77
</Setting>
88
<Setting Name="LAYER_TEXT" Type="System.String" Scope="Application">
99
<Value Profile="(Default)">MORT {0}
1010
레이어 번역창</Value>
1111
</Setting>
1212
<Setting Name="MORT_VERSION_VALUE" Type="System.Int32" Scope="Application">
13-
<Value Profile="(Default)">1305</Value>
13+
<Value Profile="(Default)">1306</Value>
1414
</Setting>
1515
<Setting Name="TOOLTIP_LIST" Type="System.String" Scope="Application">
1616
<Value Profile="(Default)">MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -45,7 +45,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
4545
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</Value>
4646
</Setting>
4747
<Setting Name="MORT_RELEASE" Type="System.String" Scope="Application">
48-
<Value Profile="(Default)">2025 12 14</Value>
48+
<Value Profile="(Default)">2025 12 28</Value>
4949
</Setting>
5050
<Setting Name="BASIC_TEXT" Type="System.String" Scope="Application">
5151
<Value Profile="(Default)">Monkeyhead's OCR Realtime TransLate {0}

MORT/app.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
<applicationSettings>
7474
<MORT.Properties.Settings>
7575
<setting name="MORT_VERSION" serializeAs="String">
76-
<value>1.305V</value>
76+
<value>1.306V</value>
7777
</setting>
7878
<setting name="LAYER_TEXT" serializeAs="String">
7979
<value>MORT {0}
8080
레이어 번역창</value>
8181
</setting>
8282
<setting name="MORT_VERSION_VALUE" serializeAs="String">
83-
<value>1305</value>
83+
<value>1306</value>
8484
</setting>
8585
<setting name="TOOLTIP_LIST" serializeAs="String">
8686
<value>MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -115,7 +115,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
115115
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</value>
116116
</setting>
117117
<setting name="MORT_RELEASE" serializeAs="String">
118-
<value>2025 12 14</value>
118+
<value>2025 12 28</value>
119119
</setting>
120120
<setting name="BASIC_TEXT" serializeAs="String">
121121
<value>Monkeyhead's OCR Realtime TransLate {0}

0 commit comments

Comments
 (0)