From 572cb273fa488682f304afd90e995e63e77dcc1f Mon Sep 17 00:00:00 2001 From: Mario Idival Date: Wed, 23 Sep 2015 13:58:00 -0300 Subject: [PATCH] using gosseract to extract text of images --- images.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 images.go diff --git a/images.go b/images.go new file mode 100644 index 0000000..418adff --- /dev/null +++ b/images.go @@ -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 +}