diff options
author | Nick White <git@njw.name> | 2019-10-30 13:01:17 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-10-30 13:01:17 +0000 |
commit | 9060bc1bf6c90d21f67de77d3f95c0de84f41d68 (patch) | |
tree | 5ce361d2a30dba6feede4c9782795c543936d81e /pkg/hocr | |
parent | 1cfe06589c738c22161a19fccaa5bc72d8f72da0 (diff) |
Simplify and document hocr package slightly better
Diffstat (limited to 'pkg/hocr')
-rw-r--r-- | pkg/hocr/lines.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/pkg/hocr/lines.go b/pkg/hocr/lines.go index d2983be..3e4dc65 100644 --- a/pkg/hocr/lines.go +++ b/pkg/hocr/lines.go @@ -9,7 +9,6 @@ import ( _ "image/jpeg" _ "image/png" "io/ioutil" - "log" "os" "path/filepath" "strings" @@ -85,6 +84,8 @@ func parseLineDetails(h Hocr, i *image.Gray, name string) (line.Details, error) return lines, nil } +// GetLineDetails parses a hocr file and returns a corresponding +// line.Details, including image extracts for each line. func GetLineDetails(hocrfn string) (line.Details, error) { var newlines line.Details @@ -102,14 +103,10 @@ func GetLineDetails(hocrfn string) (line.Details, error) { var gray *image.Gray pngfn := strings.Replace(hocrfn, ".hocr", ".png", 1) pngf, err := os.Open(pngfn) - if err != nil { - log.Println("Warning: can't open image %s\n", pngfn) - } else { + if err == nil { defer pngf.Close() img, _, err = image.Decode(pngf) - if err != nil { - log.Println("Warning: can't load image %s\n", pngfn) - } else { + if err == nil { b := img.Bounds() gray = image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(gray, b, img, b.Min, draw.Src) @@ -120,6 +117,8 @@ func GetLineDetails(hocrfn string) (line.Details, error) { return parseLineDetails(h, gray, n) } +// GetLineBasics parses a hocr file and returns a corresponding +// line.Details, without any image extracts. func GetLineBasics(hocrfn string) (line.Details, error) { var newlines line.Details |