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 938e5c6 commit 92ed2f3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kernel/util/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

0 comments on commit 92ed2f3

Please sign in to comment.