overlay and calibration
This commit is contained in:
parent
3062993f7c
commit
3456e0d62a
24 changed files with 1193 additions and 439 deletions
|
|
@ -6,6 +6,32 @@ using OpenCvSharp.Extensions;
|
|||
|
||||
static class ImagePreprocessor
|
||||
{
|
||||
/// <summary>
|
||||
/// CLAHE (Contrast Limited Adaptive Histogram Equalization) preprocessing.
|
||||
/// Enhances local contrast — works for both light and dark text on varying backgrounds.
|
||||
/// Pipeline: grayscale -> CLAHE -> upscale (keeps grayscale, lets EasyOCR handle binarization)
|
||||
/// </summary>
|
||||
public static Bitmap PreprocessClahe(Bitmap src, double clipLimit = 3.0, int tileSize = 8, int upscale = 2)
|
||||
{
|
||||
using var mat = BitmapConverter.ToMat(src);
|
||||
using var gray = new Mat();
|
||||
Cv2.CvtColor(mat, gray, ColorConversionCodes.BGRA2GRAY);
|
||||
|
||||
using var clahe = Cv2.CreateCLAHE(clipLimit, new OpenCvSharp.Size(tileSize, tileSize));
|
||||
using var enhanced = new Mat();
|
||||
clahe.Apply(gray, enhanced);
|
||||
|
||||
if (upscale > 1)
|
||||
{
|
||||
using var upscaled = new Mat();
|
||||
Cv2.Resize(enhanced, upscaled, new OpenCvSharp.Size(enhanced.Width * upscale, enhanced.Height * upscale),
|
||||
interpolation: InterpolationFlags.Cubic);
|
||||
return BitmapConverter.ToBitmap(upscaled);
|
||||
}
|
||||
|
||||
return BitmapConverter.ToBitmap(enhanced);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pre-process an image for OCR using morphological white top-hat filtering.
|
||||
/// Isolates bright tooltip text, suppresses dim background text visible through overlay.
|
||||
|
|
|
|||
|
|
@ -54,6 +54,12 @@ public class ScreenReader : IScreenReader
|
|||
return Task.FromResult(_pythonBridge.OcrFromBitmap(processed));
|
||||
}
|
||||
|
||||
if (preprocess == "clahe")
|
||||
{
|
||||
using var processed = ImagePreprocessor.PreprocessClahe(bitmap);
|
||||
return Task.FromResult(_pythonBridge.OcrFromBitmap(processed));
|
||||
}
|
||||
|
||||
return Task.FromResult(_pythonBridge.OcrFromBitmap(bitmap));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue