using gosseract to extract text of images

This commit is contained in:
Mario Idival
2015-09-23 13:58:00 -03:00
parent 5d7149066b
commit 572cb273fa
+25
View File
@@ -0,0 +1,25 @@
package docconv
import (
"fmt"
"io"
"github.com/otiai10/gosseract"
)
func ConvertImage(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
meta := make(map[string]string)
out := make(chan string, 1)
go func(file *LocalFile) {
body := gosseract.Must(gosseract.Params{Src: file.Name()})
out <- string(body)
}(f)
return <-out, meta, nil
}