added tesseract threads
This commit is contained in:
parent
55b8218860
commit
84d48a6eea
4 changed files with 41 additions and 21 deletions
|
|
@ -13,11 +13,15 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
const pdfExt = ".pdf"
|
||||
const (
|
||||
pdfExt = ".pdf"
|
||||
|
||||
minThreads = 1
|
||||
maxThreads = 4
|
||||
)
|
||||
|
||||
type PDF struct {
|
||||
cmd string
|
||||
|
|
@ -46,7 +50,7 @@ type Scanner struct {
|
|||
p PDF
|
||||
}
|
||||
|
||||
func New(base string, langs []string, timeout time.Duration) (s *Scanner, err error) {
|
||||
func New(base string, langs []string, threads int, timeout time.Duration) (s *Scanner, err error) {
|
||||
var (
|
||||
tcmd string
|
||||
pcmd string
|
||||
|
|
@ -77,11 +81,16 @@ func New(base string, langs []string, timeout time.Duration) (s *Scanner, err er
|
|||
lang += "+"
|
||||
}
|
||||
}
|
||||
if threads > maxThreads {
|
||||
threads = maxThreads
|
||||
} else if threads < minThreads {
|
||||
threads = minThreads
|
||||
}
|
||||
args := []string{"-l", lang, "--oem", tesseract_oem}
|
||||
s = &Scanner{
|
||||
base,
|
||||
timeout,
|
||||
Tesseract{tcmd, args, []string{fmt.Sprintf("OMP_THREAD_LIMIT=%d", runtime.NumCPU())}},
|
||||
Tesseract{tcmd, args, []string{fmt.Sprintf("OMP_THREAD_LIMIT=%d", threads)}},
|
||||
PDF{pcmd, []string{"-layout", "-nopgbrk", "-eol", "unix"}},
|
||||
}
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue