1 Star 0 Fork 1

AAAA建材批发/gosseract

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tesseract0304.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
Eivind Siqveland Larsen 提交于 2015-07-26 04:02 +08:00 . add tesseract 3.04 support
package gosseract
import "fmt"
import "os"
import "os/exec"
import "bytes"
import "io/ioutil"
type tesseract0304 struct {
version string
resultFilePath string
commandPath string
}
func (t tesseract0304) Version() string {
return t.version
}
func (t tesseract0304) 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 tesseract0304) 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

搜索帮助