summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hocr/hocr.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/hocr/hocr.go b/lib/hocr/hocr.go
index f6316d8..bfc6a98 100644
--- a/lib/hocr/hocr.go
+++ b/lib/hocr/hocr.go
@@ -98,3 +98,28 @@ func GetText(hocrfn string) (string, error) {
}
return s, nil
}
+
+func GetAvgConf(hocrfn string) (float64, error) {
+ file, err := ioutil.ReadFile(hocrfn)
+ if err != nil {
+ return 0, err
+ }
+
+ h, err := Parse(file)
+ if err != nil {
+ return 0, err
+ }
+
+ var total, num float64
+ for _, l := range h.Lines {
+ for _, w := range l.Words {
+ c, err := wordConf(w.Title)
+ if err != nil {
+ return 0, err
+ }
+ total += c
+ num++
+ }
+ }
+ return total / num, nil
+}