easyocr work
This commit is contained in:
parent
9f208b0606
commit
735b6f7157
7 changed files with 121 additions and 10 deletions
|
|
@ -105,9 +105,10 @@ static class Daemon
|
|||
private static object HandleDiffOcrPython(OcrHandler ocrHandler, PythonOcrBridge pythonBridge, Request request)
|
||||
{
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
var p = request.Threshold > 0
|
||||
? new DiffOcrParams { DiffThresh = request.Threshold }
|
||||
: new DiffOcrParams();
|
||||
// Use default params (same wide crop as Tesseract path).
|
||||
// Background subtraction below eliminates stash items from the image.
|
||||
var p = new DiffOcrParams();
|
||||
if (request.Threshold > 0) p.DiffThresh = request.Threshold;
|
||||
|
||||
var cropResult = ocrHandler.DiffCrop(request, p);
|
||||
if (cropResult == null)
|
||||
|
|
@ -115,22 +116,29 @@ static class Daemon
|
|||
|
||||
var (cropped, refCropped, current, region) = cropResult.Value;
|
||||
using var _current = current;
|
||||
using var _refCropped = refCropped;
|
||||
|
||||
// Apply background subtraction to isolate tooltip text.
|
||||
// This removes stash items and game world — only tooltip text remains.
|
||||
// No upscale (upscale=1) to keep the image small for EasyOCR speed.
|
||||
// Hard threshold (softThreshold=false) produces clean binary for OCR.
|
||||
using var processed = ImagePreprocessor.PreprocessWithBackgroundSub(
|
||||
cropped, refCropped, dimPercentile: 40, textThresh: 60, upscale: 1, softThreshold: false);
|
||||
cropped.Dispose();
|
||||
refCropped.Dispose();
|
||||
var diffMs = sw.ElapsedMilliseconds;
|
||||
|
||||
// Save crop to requested path if provided
|
||||
// Save processed crop if path provided
|
||||
if (!string.IsNullOrEmpty(request.Path))
|
||||
{
|
||||
var dir = Path.GetDirectoryName(request.Path);
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
cropped.Save(request.Path, ImageUtils.GetImageFormat(request.Path));
|
||||
processed.Save(request.Path, ImageUtils.GetImageFormat(request.Path));
|
||||
}
|
||||
|
||||
// Send crop to Python via base64 over pipe (no temp file I/O)
|
||||
// Send processed image to Python OCR via base64
|
||||
sw.Restart();
|
||||
var ocrResult = pythonBridge.OcrFromBitmap(cropped, request.Engine!);
|
||||
cropped.Dispose();
|
||||
var ocrResult = pythonBridge.OcrFromBitmap(processed, request.Engine!);
|
||||
var ocrMs = sw.ElapsedMilliseconds;
|
||||
|
||||
Console.Error.WriteLine($" diff-ocr-python: diff={diffMs}ms ocr={ocrMs}ms total={diffMs + ocrMs}ms crop={region.Width}x{region.Height}");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue