added test cases

This commit is contained in:
Boki 2026-02-12 13:08:19 -05:00
parent c1892230b7
commit 93e2234c4e
9 changed files with 320 additions and 141 deletions

View file

@ -108,6 +108,8 @@ static class Daemon
var engine = request.Engine ?? "tesseract";
var preprocess = request.Preprocess ?? "none";
var kernelSize = request.Params?.KernelSize ?? 41;
// No preprocess + tesseract = original fast path
if (engine == "tesseract" && preprocess == "none")
return ocrHandler.HandleOcr(request);
@ -119,7 +121,7 @@ static class Daemon
Bitmap processed;
if (preprocess == "tophat")
{
processed = ImagePreprocessor.PreprocessForOcr(bitmap);
processed = ImagePreprocessor.PreprocessForOcr(bitmap, kernelSize: kernelSize);
}
else if (preprocess == "bgsub")
{
@ -152,16 +154,24 @@ static class Daemon
private static object HandleDiffOcrPipeline(OcrHandler ocrHandler, PythonOcrBridge pythonBridge, Request request)
{
var engine = request.Engine ?? "tesseract";
var preprocess = request.Preprocess ?? "bgsub";
var isPythonEngine = engine is "easyocr" or "paddleocr";
var p = request.Params?.Clone() ?? new DiffOcrParams();
if (request.Threshold > 0) p.DiffThresh = request.Threshold;
// No engine override + no preprocess override = original Tesseract path (supports test/tune params)
if (engine == "tesseract" && request.Preprocess == null)
// Determine preprocess mode: explicit request.Preprocess > params.UseBackgroundSub > default "bgsub"
string preprocess;
if (request.Preprocess != null)
preprocess = request.Preprocess;
else if (request.Params != null)
preprocess = p.UseBackgroundSub ? "bgsub" : "tophat";
else
preprocess = "bgsub";
// No engine override + no preprocess override + no params = original Tesseract path
if (engine == "tesseract" && request.Preprocess == null && request.Params == null)
return ocrHandler.HandleDiffOcr(request);
var sw = System.Diagnostics.Stopwatch.StartNew();
var p = new DiffOcrParams();
if (request.Threshold > 0) p.DiffThresh = request.Threshold;
var cropResult = ocrHandler.DiffCrop(request, p);
if (cropResult == null)
@ -174,13 +184,14 @@ static class Daemon
Bitmap processed;
if (preprocess == "bgsub")
{
int upscale = isPythonEngine ? 1 : 2;
int upscale = isPythonEngine ? 1 : p.Upscale;
processed = ImagePreprocessor.PreprocessWithBackgroundSub(
cropped, refCropped, dimPercentile: 40, textThresh: 60, upscale: upscale, softThreshold: false);
cropped, refCropped, dimPercentile: p.DimPercentile, textThresh: p.TextThresh,
upscale: upscale, softThreshold: p.SoftThreshold);
}
else if (preprocess == "tophat")
{
processed = ImagePreprocessor.PreprocessForOcr(cropped);
processed = ImagePreprocessor.PreprocessForOcr(cropped, kernelSize: p.KernelSize);
}
else // "none"
{

View file

@ -45,6 +45,9 @@ class Request
[JsonPropertyName("preprocess")]
public string? Preprocess { get; set; }
[JsonPropertyName("params")]
public DiffOcrParams? Params { get; set; }
}
class RegionRect

View file

@ -49,5 +49,31 @@
"Asking Price:",
"35x Divine Orb"
]
},
{
"id": "raphpith1",
"image": "images/raphpith.png",
"fullImage": "images/raphpith-snapshot.png",
"expected": [
"RATHPITH GLOBE",
"SACRED Focus",
"Focus",
"Quality: +20%",
"Energy Shield: 104",
"Requires: Level 75",
"16% Increased Energy Shield",
"+24 To Maximum Mana",
"+5% to all Elemental Resistances",
"NON-CHANNELLING SPELLS HAVE 3% INCREASED MAGNITUDE OF AlLMENTS PER 100 MAXIMUM LIFE",
"NON-CHANNELLING SPELLS DEAL 6% INCREASED DAMAGE PER 100 MAXIMUM MANA",
"+72 TO MAXIMUM LIFE",
"NON-CHANNELLING SPELLS HAVE 3% INCREASED CRITICAL HIT CHANCE PER 100 MAXIMUM LIFE",
"NON-CHANNELLING SPELLS DEAL 6% INCREASED DAMACE PER 100 MAXIMUM LIFE",
"Twice Corrupted",
"THE VAAL EMPTIED THEIR SLAVES OF BEATING HEARTS",
"AND LEFT A MOUNTAIN OF TWITCHING DEAD",
"Asking Price:",
"120x Divine Orb"
]
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 MiB