From 0efed080dec35be85bd8f0388a062c79c5ac544a Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 24 Jan 2019 18:13:35 +0000 Subject: Better separation between library and tool --- bucket-lines/bucket-lines.go | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'bucket-lines') diff --git a/bucket-lines/bucket-lines.go b/bucket-lines/bucket-lines.go index ad73fcd..186f568 100644 --- a/bucket-lines/bucket-lines.go +++ b/bucket-lines/bucket-lines.go @@ -3,51 +3,18 @@ package main import ( "flag" "fmt" - "image/png" - "io/ioutil" "log" "os" "path/filepath" - "strings" "git.rescribe.xyz/testingtools/parse" "git.rescribe.xyz/testingtools/parse/hocr" "git.rescribe.xyz/testingtools/parse/prob" ) -// TODO: maybe move this into hocr.go -func detailsFromHocr(f string) (parse.LineDetails, error) { - var newlines parse.LineDetails - - file, err := ioutil.ReadFile(f) - if err != nil { - return newlines, err - } - - h, err := hocr.Parse(file) - if err != nil { - return newlines, err - } - - pngfn := strings.Replace(f, ".hocr", ".png", 1) - pngf, err := os.Open(pngfn) - if err != nil { - return newlines, err - } - defer pngf.Close() - img, err := png.Decode(pngf) - if err != nil { - return newlines, err - } - - n := strings.Replace(filepath.Base(f), ".hocr", "", 1) - return hocr.GetLineDetails(h, img, n) -} - func main() { - // TODO: Allow different specs to be used for .prob vs .hocr. Do this - // by adding a field to LineDetails that is linked to a named - // BucketSpecs. + // TODO: Allow bucket specs to be determined by a json file passed + // as an argument. b := parse.BucketSpecs{ // minimum confidence, name { 0, "bad" }, @@ -83,7 +50,7 @@ func main() { case ".prob": newlines, err = prob.GetLineDetails(f) case ".hocr": - newlines, err = detailsFromHocr(f) + newlines, err = hocr.GetLineDetails(f) default: log.Printf("Skipping file '%s' as it isn't a .prob or .hocr\n", f) } -- cgit v1.2.1-24-ge1ad