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 {