From 92ed2f38e77431cd8f9a2ccf0823b6db2a21932a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 16 Jan 2023 11:46:51 +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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index a36688602..78960cd1f 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -82,9 +82,10 @@ func Tesseract(imgAbsPath string) string { defer logging.Recover() - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() + now := time.Now() cmd := exec.CommandContext(ctx, "tesseract", "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", "chi_sim+eng") gulu.CmdAttr(cmd) output, err := cmd.CombinedOutput() @@ -108,7 +109,7 @@ func Tesseract(imgAbsPath string) string { ret := string(output) ret = strings.ReplaceAll(ret, "\r", "") ret = strings.ReplaceAll(ret, "\n", "") - logging.LogInfof("tesseract [path=%s, size=%d]: %s", imgAbsPath, info.Size(), ret) + logging.LogInfof("tesseract [path=%s, size=%d, text=%s, elapsed=%dms]", imgAbsPath, info.Size(), ret, time.Since(now).Milliseconds()) ocrResultCache.Set(imgAbsPath, ret, info.Size()) return ret }