From 9060bc1bf6c90d21f67de77d3f95c0de84f41d68 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 30 Oct 2019 13:01:17 +0000 Subject: Simplify and document hocr package slightly better --- pkg/hocr/lines.go | 13 ++++++------- 1 file 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 -- cgit v1.2.1-24-ge1ad