Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 桌面端支持搜索图片中的文本 Fix https://github.com/siyuan-note/siyuan/issues/3470

Liang Ding938e5c677a12
diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go
index bd5b4c231f..a366886024 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", "")