mirror of
https://github.com/sajari/docconv.git
synced 2026-10-17 05:30:56 +08:00
using gosseract to extract text of images
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user