summaryrefslogtreecommitdiff
path: root/pkg/line/line.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-08 15:49:52 +0100
committerNick White <git@njw.name>2019-10-08 15:49:52 +0100
commit69aae6b93dcadd9e4895f86fe661ee80e79dcf9e (patch)
treebfc42b832a6d6e3051631eb6cf530e1400b2c080 /pkg/line/line.go
parentd43c11bf653bfe3c1ad1ed277f1ec08bf155cf98 (diff)
Remove parts that have been moved elsewhere, and rename to rescribe.xyz/utils
bookpipeline is now at rescribe.xyz/bookpipeline preproc is now at rescribe.xyz/preproc integralimg is now at rescribe.xyz/preproc/integralimg
Diffstat (limited to 'pkg/line/line.go')
-rw-r--r--pkg/line/line.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/pkg/line/line.go b/pkg/line/line.go
new file mode 100644
index 0000000..d4e3e44
--- /dev/null
+++ b/pkg/line/line.go
@@ -0,0 +1,57 @@
+package line
+
+import (
+ "image"
+ "image/png"
+ "io"
+ "os"
+)
+
+type Detail struct {
+ Name string
+ Avgconf float64
+ Img CopyableImg
+ Text string
+ OcrName string
+}
+
+type CopyableImg interface {
+ CopyLineTo(io.Writer) error
+}
+
+type Details []Detail
+
+func (l Details) Len() int { return len(l) }
+func (l Details) Less(i, j int) bool { return l[i].Avgconf < l[j].Avgconf }
+func (l Details) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
+
+// This is an implementation of the CopyableImg 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
+}
+
+// This is an implementation of the CopyableImg interface that
+// stores the path of an image
+type ImgPath struct {
+ Path string
+}
+
+func (i ImgPath) CopyLineTo(w io.Writer) error {
+ f, err := os.Open(i.Path)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ _, err = io.Copy(w, f)
+ return err
+}