Last active
August 8, 2019 15:06
-
-
Save samuell/56ac30625417b881427dfea7d2675d43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
sp "github.com/scipipe/scipipe" | |
comp "github.com/scipipe/scipipe/components" | |
"io/ioutil" | |
"strings" | |
) | |
func main() { | |
path := "data/*.pdf" | |
wf := sp.NewWorkflow("pdf2ocr", 20) | |
globpdf := comp.NewFileGlobber(wf, "findpdf", path) | |
ximages := wf.NewProc("pdfimages", "pdfimages -tiff -p \"{i:in}\" \"{i:in}\" ; ls \"{i:in}\"*.tif > {o:out} ") // {o:out} | |
ximages.In("in").From(globpdf.Out()) | |
ocr := wf.NewProc("tesseract", "# Just create the ports: {i:tiffiles} {o:out}") | |
ocr.CustomExecute = func(t *sp.Task) { | |
tiffiles, err := ioutil.ReadFile(t.InPath("tiffiles")) | |
sp.Check(err) | |
tifFiles := strings.Split(string(tiffiles), "\n") | |
for _, tifFile := range tifFiles { | |
sp.ExecCmd(fmt.Sprintf("tesseract %s %s.ocr -psm 1 -l eng && ls %s*.txt >> %s", tifFile, tifFile, tifFile, t.OutIP("out").TempPath())) | |
} | |
} | |
ocr.In("tiffiles").From(ximages.Out("out")) | |
ocr.SetOut("out", "{i:tiffiles}.tesseract.out") | |
wf.Run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment