From 2936240df8b25a15306fe446eaae10ab3bb58300 Mon Sep 17 00:00:00 2001 From: simon987 Date: Sun, 10 Dec 2023 09:20:11 -0500 Subject: [PATCH] Disable OSD, add preserve_interword_spaces for chi_sim OCR (#443) --- third-party/libscan/libscan/ocr/ocr.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/third-party/libscan/libscan/ocr/ocr.h b/third-party/libscan/libscan/ocr/ocr.h index 64699cd..2b2086b 100644 --- a/third-party/libscan/libscan/ocr/ocr.h +++ b/third-party/libscan/libscan/ocr/ocr.h @@ -5,7 +5,7 @@ #include #define MIN_OCR_WIDTH 350 -#define MIN_OCR_HEIGHT 100 +#define MIN_OCR_HEIGHT 33 #define MIN_OCR_LEN 10 #define OCR_IS_VALID_BPP(d) \ @@ -28,7 +28,13 @@ ocr_extract_text(const char *tesseract_path, const char *tesseract_lang, TessBaseAPI *api = TessBaseAPICreate(); TessBaseAPIInit3(api, tesseract_path, tesseract_lang); - TessBaseAPISetPageSegMode(api, PSM_AUTO_OSD); + // https://github.com/simon987/sist2/issues/443 + if (strstr(tesseract_lang, "chi") != NULL) { + TessBaseAPISetVariable(api, "preserve_interword_spaces", "1"); + } + + // TODO: add this as param? +// TessBaseAPISetPageSegMode(api, PSM_AUTO_OSD); TessBaseAPISetImage(api, img_buf, img_w, img_h, img_bpp, img_stride); TessBaseAPISetSourceResolution(api, img_xres); @@ -39,6 +45,9 @@ ocr_extract_text(const char *tesseract_path, const char *tesseract_lang, if (len >= MIN_OCR_LEN) { cb(text, len); } + + fprintf(stderr, "OCR: '%s'\n", text); + TessDeleteText(text); }