summaryrefslogtreecommitdiff
path: root/cmd/pagegraph/main.go
blob: b941a6de481027e2fdf9bb5366988c6fccb08d19 (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
53
54
55
56
57
package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"path/filepath"

	"rescribe.xyz/bookpipeline"
	"rescribe.xyz/utils/pkg/hocr"
)

func main() {
	flag.Usage = func() {
		fmt.Fprintln(flag.CommandLine.Output(), "Usage: pagegraph file.hocr graph.png")
		flag.PrintDefaults()
	}
	flag.Parse()

	if flag.NArg() != 2 {
		flag.Usage()
		return
	}

	linedetails, err := hocr.GetLineDetails(flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}
	var confs []*bookpipeline.Conf
	for n, wc := range linedetails {
		c := bookpipeline.Conf{
			Conf: wc.Avgconf * 100,
			//Path: "fakepath",
			Path: fmt.Sprintf("line_%d", n),
		}
		confs = append(confs, &c)
	}

	// Structure to fit what bookpipeline.Graph needs
	// TODO: probably reorganise bookpipeline to just need []*Conf
	cconfs := make(map[string]*bookpipeline.Conf)
	for _, c := range confs {
		cconfs[c.Path] = c
	}

	fn := flag.Arg(1)
	f, err := os.Create(fn)
	if err != nil {
		log.Fatalln("Error creating file", fn, err)
	}
	defer f.Close()
	err = bookpipeline.GraphOpts(cconfs, filepath.Base(flag.Arg(0)), "Line number", false, f)
	if err != nil {
		log.Fatalln("Error creating graph", err)
	}
}