Skip to content

Commit

Permalink
🎨 桌面端支持搜索图片中的文本 Fix #3470
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 16, 2023
1 parent 83c1aaa commit 938e5c6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion kernel/util/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
"github.com/siyuan-note/logging"
)

var tesseractEnabled bool
var (
tesseractEnabled bool
tesseractErrCnt int
)

func initTesseract() {
ver := getTesseractVer()
Expand Down Expand Up @@ -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", "")
Expand Down

0 comments on commit 938e5c6

Please sign in to comment.