finished easyocr and pipeline

This commit is contained in:
Boki 2026-02-12 11:24:31 -05:00
parent 735b6f7157
commit cf5d944fd1
8 changed files with 252 additions and 51 deletions

View file

@ -401,6 +401,33 @@ class OcrHandler(TesseractEngine engine)
}
}
/// <summary>
/// Run Tesseract OCR on an already-preprocessed bitmap. Converts to Mat, pads,
/// runs PSM-6, and adjusts word coordinates to screen space using the supplied region.
/// </summary>
public DiffOcrResponse RunTesseractOnBitmap(Bitmap processedBmp, RegionRect region, int pad = 10, int upscale = 2, int psm = 6)
{
using var processedMat = BitmapConverter.ToMat(processedBmp);
using var padded = new Mat();
Cv2.CopyMakeBorder(processedMat, padded, pad, pad, pad, pad, BorderTypes.Constant, Scalar.White);
using var bmp = BitmapConverter.ToBitmap(padded);
using var pix = ImageUtils.BitmapToPix(bmp);
using var page = engine.Process(pix, (PageSegMode)psm);
var text = page.GetText();
int effUpscale = upscale > 0 ? upscale : 1;
var lines = ImageUtils.ExtractLinesFromPage(page,
offsetX: region.X - pad / effUpscale,
offsetY: region.Y - pad / effUpscale);
return new DiffOcrResponse
{
Text = text,
Lines = lines,
Region = region,
};
}
public object HandleTest(Request req) => RunTestCases(new DiffOcrParams(), verbose: true);
public object HandleTune(Request req)