added tesseract threads
This commit is contained in:
parent
55b8218860
commit
84d48a6eea
4 changed files with 41 additions and 21 deletions
|
|
@ -29,7 +29,8 @@ const (
|
|||
defRunUser = "docstore"
|
||||
defRunGroup = "docstore"
|
||||
|
||||
defTimeout = 600
|
||||
defTimeout = 600
|
||||
tesseractThreads = 1
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -71,8 +72,11 @@ func initServer(cfg core.Config) (err error) {
|
|||
log.InitLogger(cfg)
|
||||
|
||||
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
|
||||
debugCfg := cfg
|
||||
debugCfg.Secret = "***hidden***"
|
||||
log.Debugf("docstore config: %+v", debugCfg)
|
||||
|
||||
scanner, err := scan.New(cfg.DataDir, cfg.Langs, time.Second*time.Duration(cfg.CMDTimeout))
|
||||
scanner, err := scan.New(cfg.DataDir, cfg.Langs, cfg.TesseractThreads, time.Second*time.Duration(cfg.CMDTimeout))
|
||||
if err != nil {
|
||||
return errors.New("scanner: " + err.Error())
|
||||
}
|
||||
|
|
@ -255,6 +259,12 @@ func serverFlags() []cli.Flag {
|
|||
Usage: "timeout in seconds for executed teseract and pdftotext commands",
|
||||
Destination: &config.CMDTimeout,
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "threads",
|
||||
Value: tesseractThreads,
|
||||
Usage: "tesseract thread limit (1-4)",
|
||||
Destination: &config.TesseractThreads,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "foreground, f",
|
||||
Usage: "do not fork into the background",
|
||||
|
|
|
|||
|
|
@ -34,17 +34,18 @@ func (p Paths) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
|||
func (p Paths) Less(i, j int) bool { return p[i].Name < p[j].Name }
|
||||
|
||||
type Config struct {
|
||||
RunDir string `json:"run_dir,omitempty"`
|
||||
DataDir string `json:"-"`
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
ListenAddr string `json:"listen_addr,omitempty"`
|
||||
LogFile string `json:"log_file,omitempty"`
|
||||
Version string `json:"-"`
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Langs []string `json:"langs,omitempty"`
|
||||
CMDTimeout int `json:"cmd_timeout,omitempty"`
|
||||
Foreground bool `json:"foreground,omitempty"`
|
||||
SecureCookie bool `json:"secure_cookie,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
RunDir string `json:"run_dir,omitempty"`
|
||||
DataDir string `json:"-"`
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
ListenAddr string `json:"listen_addr,omitempty"`
|
||||
LogFile string `json:"log_file,omitempty"`
|
||||
Version string `json:"-"`
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Langs []string `json:"langs,omitempty"`
|
||||
CMDTimeout int `json:"cmd_timeout,omitempty"`
|
||||
TesseractThreads int `json:"tesseract_threads,omitempty"`
|
||||
Foreground bool `json:"foreground,omitempty"`
|
||||
SecureCookie bool `json:"secure_cookie,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ const (
|
|||
<td>File</td>
|
||||
<td><div class="btn-group">
|
||||
{{if $item.Scan}}
|
||||
<a href="#" class="btn btn-sm btn-warning">Scanning..</a>
|
||||
<a href="#" class="btn btn-sm btn-warning">Scanning</a>
|
||||
{{else}}
|
||||
{{if not $item.Flag}}
|
||||
<a href="/index{{$item.Abs}}" class="btn btn-sm btn-success">Index</a>
|
||||
|
|
@ -109,7 +109,7 @@ const (
|
|||
</ol>
|
||||
<div class="btn-group btn-breadcrumb">
|
||||
{{if .Data.Scan}}
|
||||
<a href="#" class="btn btn-sm btn-warning">Scanning..</a>
|
||||
<a href="#" class="btn btn-sm btn-warning">Scanning</a>
|
||||
{{else}}
|
||||
{{if not .Data.Flag}}
|
||||
<a href="/index{{.Data.Name}}" class="btn btn-sm btn-success">Index</a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue