diff options
author | Nick White <git@njw.name> | 2019-01-23 20:47:33 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-01-23 20:47:33 +0000 |
commit | d256f967a26ceeb7c3987a1fc447b126a35054f9 (patch) | |
tree | f80c1e3e2c3757c59ad51dec98de5b6e82a426fa /parse/line.go | |
parent | c41aa16d8a3d35ce4185184ee50536bf2089a120 (diff) |
Separate out hocr parts from line parts
Diffstat (limited to 'parse/line.go')
-rw-r--r-- | parse/line.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/parse/line.go b/parse/line.go new file mode 100644 index 0000000..3ddde76 --- /dev/null +++ b/parse/line.go @@ -0,0 +1,51 @@ +package parse + +// TODO: integrate in line-conf-buckets linedetail +// TODO: add BucketUp() function here that does what both line-conf-buckets-tess.go +// and line-conf-buckets.go do +// TODO: consider naming this package line, and separating it from hocr and prob + +import ( + "image" + "image/png" + "io" +) + +type LineDetail struct { + Name string + Avgconf float64 + Img CopyableLine + Text string + Hocrname string +} + +type CopyableLine interface { + CopyLineTo(io.Writer) (error) +} + +// This is an implementation of the CopyableLine interface that +// stores the image directly as an image.Image +type ImgDirect struct { + Img image.Image +} + +func (i ImgDirect) CopyLineTo(w io.Writer) (error) { + err := png.Encode(w, i.Img) + if err != nil { + return err + } + return nil +} + +type LineDetails []LineDetail + +// Used by sort.Sort. +func (l LineDetails) Len() int { return len(l) } + +// Used by sort.Sort. +func (l LineDetails) Less(i, j int) bool { + return l[i].Avgconf < l[j].Avgconf +} + +// Used by sort.Sort. +func (l LineDetails) Swap(i, j int) { l[i], l[j] = l[j], l[i] } |