mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🐛 macOS 端 Tesseract OCR 安装后不识别 https://github.com/siyuan-note/siyuan/issues/7107
This commit is contained in:
parent
599afa2ac9
commit
68491d47f0
1 changed files with 12 additions and 7 deletions
|
|
@ -33,6 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
TesseractBin = "tesseract"
|
||||||
TesseractEnabled bool
|
TesseractEnabled bool
|
||||||
AssetsTexts = map[string]string{}
|
AssetsTexts = map[string]string{}
|
||||||
AssetsTextsLock = sync.Mutex{}
|
AssetsTextsLock = sync.Mutex{}
|
||||||
|
|
@ -74,7 +75,7 @@ func Tesseract(imgAbsPath string) string {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 7*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 7*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, "tesseract", "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"))
|
cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"))
|
||||||
gulu.CmdAttr(cmd)
|
gulu.CmdAttr(cmd)
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
|
|
@ -141,14 +142,18 @@ func getTesseractVer() (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("tesseract", "--version")
|
cmd := exec.Command(TesseractBin, "--version")
|
||||||
gulu.CmdAttr(cmd)
|
gulu.CmdAttr(cmd)
|
||||||
logging.LogInfof("os env [%s]", os.Environ())
|
|
||||||
logging.LogInfof("cmd env [%s]", cmd.Environ())
|
|
||||||
cmd.Env = os.Environ()
|
|
||||||
data, err := cmd.CombinedOutput()
|
data, err := cmd.CombinedOutput()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("get tesseract version failed: %s", err)
|
if strings.Contains(err.Error(), "executable file not found") {
|
||||||
|
TesseractBin = "/usr/local/bin/tesseract"
|
||||||
|
cmd = exec.Command(TesseractBin, "--version")
|
||||||
|
gulu.CmdAttr(cmd)
|
||||||
|
data, err = cmd.CombinedOutput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logging.LogInfof("tesseract version output [%s]", string(data))
|
logging.LogInfof("tesseract version output [%s]", string(data))
|
||||||
|
|
@ -169,7 +174,7 @@ func getTesseractLangs() (ret []string) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("tesseract", "--list-langs")
|
cmd := exec.Command(TesseractBin, "--list-langs")
|
||||||
gulu.CmdAttr(cmd)
|
gulu.CmdAttr(cmd)
|
||||||
data, err := cmd.CombinedOutput()
|
data, err := cmd.CombinedOutput()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue