From 938e5c677a12790afdbd42bef210445210a287ef Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 16 Jan 2023 11:32:03 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=A1=8C=E9=9D=A2=E7=AB=AF=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=90=9C=E7=B4=A2=E5=9B=BE=E7=89=87=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=96=87=E6=9C=AC=20Fix=20https://github.com/siyuan-note/siyua?= =?UTF-8?q?n/issues/3470?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/ocr.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index bd5b4c231..a36688602 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -29,7 +29,10 @@ import ( "github.com/siyuan-note/logging" ) -var tesseractEnabled bool +var ( + tesseractEnabled bool + tesseractErrCnt int +) func initTesseract() { ver := getTesseractVer() @@ -87,14 +90,21 @@ func Tesseract(imgAbsPath string) string { output, err := cmd.CombinedOutput() if ctx.Err() == context.DeadlineExceeded { logging.LogWarnf("tesseract [path=%s, size=%d] timeout", imgAbsPath, info.Size()) + tesseractErrCnt++ return "" } if nil != err { logging.LogWarnf("tesseract [path=%s, size=%d] failed: %s", imgAbsPath, info.Size(), err) + tesseractErrCnt++ return "" } + if 16 < tesseractErrCnt { + tesseractEnabled = false + logging.LogWarnf("disable tesseract-ocr caused by too many errors") + } + ret := string(output) ret = strings.ReplaceAll(ret, "\r", "") ret = strings.ReplaceAll(ret, "\n", "")