1 Star 0 Fork 1

AAAA建材批发 / gosseract

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
tesseract0303.go 1.16 KB
Copy Edit Raw Blame History
Tom Hudson authored 2015-05-06 21:02 +08:00 . Adds 3.03 support; makes tests less brittle
package gosseract
import "fmt"
import "os"
import "os/exec"
import "bytes"
import "io/ioutil"
type tesseract0303 struct {
version string
resultFilePath string
commandPath string
}
func (t tesseract0303) Version() string {
return t.version
}
func (t tesseract0303) Execute(params []string) (res string, e error) {
// command args
var args []string
// Register source file
args = append(args, params[0])
// generate result file path
t.resultFilePath, e = generateTmpFile()
if e != nil {
return
}
// Register result file
args = append(args, t.resultFilePath)
// Register digest file
if len(params) > 1 {
args = append(args, params[1])
}
// prepare command
cmd := exec.Command(TESSERACT, args...)
// execute
var stderr bytes.Buffer
cmd.Stderr = &stderr
if e = cmd.Run(); e != nil {
e = fmt.Errorf(stderr.String())
return
}
// read result
res, e = t.readResult()
return
}
func (t tesseract0303) readResult() (res string, e error) {
fpath := t.resultFilePath + outFILEEXTENSION
file, e := os.OpenFile(fpath, 1, 1)
if e != nil {
return
}
buffer, _ := ioutil.ReadFile(file.Name())
res = string(buffer)
os.Remove(file.Name())
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/invokerwf/gosseract.git
git@gitee.com:invokerwf/gosseract.git
invokerwf
gosseract
gosseract
df11bbf9be4c

Search