mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Image OCR supports setting the timeout via the environment variable SIYUAN_TESSERACT_TIMEOUT https://github.com/siyuan-note/siyuan/issues/16419
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
aac7647ff5
commit
bebf8c8e9b
1 changed files with 10 additions and 1 deletions
|
|
@ -234,7 +234,16 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) {
|
||||||
|
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 7*time.Second)
|
timeout := 7000
|
||||||
|
timeoutEnv := os.Getenv("SIYUAN_TESSERACT_TIMEOUT")
|
||||||
|
if "" != timeoutEnv {
|
||||||
|
if timeoutParsed, parseErr := strconv.Atoi(timeoutEnv); nil == parseErr {
|
||||||
|
timeout = timeoutParsed
|
||||||
|
} else {
|
||||||
|
logging.LogWarnf("parse tesseract timeout [%s] failed: %s", timeoutEnv, parseErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"), "tsv")
|
cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"), "tsv")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue