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
53
54
55
56
57
58
59
60
61
|
package main
import (
"fmt"
"os"
"path/filepath"
"rescribe.xyz/go.git/lib/line"
)
func copylineimg(fn string, l line.Detail) error {
f, err := os.Create(fn)
if err != nil {
return err
}
defer f.Close()
return l.Img.CopyLineTo(f)
}
func htmlout(dir string, lines line.Details) error {
err := os.MkdirAll(dir, 0700)
if err != nil {
return err
}
fn := filepath.Join(dir, "index.html")
f, err := os.Create(fn)
if err != nil {
return err
}
defer f.Close()
_, err = fmt.Fprintf(f, "<!DOCTYPE html><html><head><meta charset='UTF-8'><title></title>"+
"<style>td {border: 1px solid #444}</style></head><body>\n<table>\n")
if err != nil {
return err
}
for _, l := range lines {
fn = filepath.Base(l.OcrName) + "_" + l.Name + ".png"
err = copylineimg(filepath.Join(dir, fn), l)
if err != nil {
return err
}
_, err = fmt.Fprintf(f, "<tr>\n"+
"<td><h1>%.4f%%</h1></td>\n"+
"<td>%s %s</td>\n"+
"<td><img src='%s' width='100%%' /><br />%s</td>\n"+
"</tr>\n",
l.Avgconf, l.OcrName, l.Name, fn, l.Text)
if err != nil {
return err
}
}
_, err = fmt.Fprintf(f, "</table>\n</body></html>\n")
if err != nil {
return err
}
return nil
}
|