summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-31 10:40:28 +0000
committerNick White <git@njw.name>2019-10-31 10:40:28 +0000
commita46b217fd34f1bb3ee9f675fcb24cbc9a8cc2847 (patch)
tree3e8ae3dbae63e9dd7a217f5b61c51d89f4476e48
parent9060bc1bf6c90d21f67de77d3f95c0de84f41d68 (diff)
Export a couple of more generally useful functions
-rw-r--r--pkg/hocr/hocr.go4
-rw-r--r--pkg/hocr/lines.go7
2 files changed, 5 insertions, 6 deletions
diff --git a/pkg/hocr/hocr.go b/pkg/hocr/hocr.go
index dcd0494..c3c88b3 100644
--- a/pkg/hocr/hocr.go
+++ b/pkg/hocr/hocr.go
@@ -47,7 +47,7 @@ func wordConf(s string) (float64, error) {
return strconv.ParseFloat(conf[1], 64)
}
-func boxCoords(s string) ([4]int, error) {
+func BoxCoords(s string) ([4]int, error) {
var coords [4]int
re, err := regexp.Compile(`bbox ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)`)
if err != nil {
@@ -95,7 +95,7 @@ func GetText(hocrfn string) (string, error) {
for _, l := range h.Lines {
- s += getLineText(l)
+ s += LineText(l) + "\n"
}
return s, nil
}
diff --git a/pkg/hocr/lines.go b/pkg/hocr/lines.go
index 3e4dc65..b3db161 100644
--- a/pkg/hocr/lines.go
+++ b/pkg/hocr/lines.go
@@ -16,7 +16,7 @@ import (
"rescribe.xyz/utils/pkg/line"
)
-func getLineText(l OcrLine) (string) {
+func LineText(l OcrLine) (string) {
linetext := ""
linetext = l.Text
@@ -45,7 +45,6 @@ func getLineText(l OcrLine) (string) {
}
}
linetext = strings.TrimRight(linetext, " ")
- linetext += "\n"
return linetext
}
@@ -64,7 +63,7 @@ func parseLineDetails(h Hocr, i *image.Gray, name string) (line.Details, error)
totalconf += c
}
- coords, err := boxCoords(l.Title)
+ coords, err := BoxCoords(l.Title)
if err != nil {
return lines, err
}
@@ -72,7 +71,7 @@ func parseLineDetails(h Hocr, i *image.Gray, name string) (line.Details, error)
var ln line.Detail
ln.Name = l.Id
ln.Avgconf = (totalconf / float64(num)) / 100
- ln.Text = getLineText(l)
+ ln.Text = LineText(l)
ln.OcrName = name
if i != nil {
var imgd line.ImgDirect