blob: d254f42a5f32a4b6d6dd9d074186e80b2d0c0068 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package main
import (
"flag"
"fmt"
"log"
"os"
"rescribe.xyz/go.git/lib/hocr"
"rescribe.xyz/go.git/lib/line"
)
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: pgconf hocr\n")
fmt.Fprintf(os.Stderr, "Prints the total confidence for a page, as an average of the confidence of each word.\n")
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
var err error
lines := make(line.Details, 0)
for _, f := range flag.Args() {
var newlines line.Details
newlines, err = hocr.GetLineBasics(f)
if err != nil {
log.Fatal(err)
}
for _, l := range newlines {
lines = append(lines, l)
}
}
if len(lines) == 0 {
fmt.Printf("No lines found\n")
os.Exit(0)
}
var total float64
for _, l := range lines {
total += l.Avgconf
}
avg := total / float64(len(lines))
fmt.Printf("%0.0f\n", avg * 100)
}
|