From 5593542f73b65749e7c5a250a9ed6aec4d02cfc2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 16 Jan 2023 15:39:31 +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=20OCR=20=E6=96=87?= =?UTF-8?q?=E6=9C=AC=20https://github.com/siyuan-note/siyuan/issues/3470?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/ocr.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index 34791045b..b5d9f353f 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -42,10 +42,22 @@ var ( assetsTextsChanged = false ) -func GetAssetText(assets string) string { +func GetAssetText(asset string) string { assetsTextsLock.Lock() - defer assetsTextsLock.Unlock() - return assetsTexts[assets] + ret, ok := assetsTexts[asset] + assetsTextsLock.Unlock() + if ok { + return ret + } + + assetsPath := GetDataAssetsAbsPath() + assetAbsPath := strings.TrimPrefix(asset, "assets") + assetAbsPath = filepath.Join(assetsPath, assetAbsPath) + ret = Tesseract(assetAbsPath) + assetsTextsLock.Lock() + assetsTexts[asset] = ret + assetsTextsLock.Unlock() + return ret } func Tesseract(imgAbsPath string) string {