From 69aae6b93dcadd9e4895f86fe661ee80e79dcf9e Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 8 Oct 2019 15:49:52 +0100 Subject: Remove parts that have been moved elsewhere, and rename to rescribe.xyz/utils bookpipeline is now at rescribe.xyz/bookpipeline preproc is now at rescribe.xyz/preproc integralimg is now at rescribe.xyz/preproc/integralimg --- pkg/prob/prob.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pkg/prob/prob.go (limited to 'pkg/prob') diff --git a/pkg/prob/prob.go b/pkg/prob/prob.go new file mode 100644 index 0000000..8bdb3d5 --- /dev/null +++ b/pkg/prob/prob.go @@ -0,0 +1,69 @@ +package prob + +import ( + "io/ioutil" + "path/filepath" + "strconv" + "strings" + + "rescribe.xyz/utils/pkg/line" +) + +func getLineAvg(f string) (float64, error) { + totalconf := float64(0) + num := 0 + + prob, err := ioutil.ReadFile(f) + if err != nil { + return 0, err + } + + for _, l := range strings.Split(string(prob), "\n") { + fields := strings.Fields(l) + + if len(fields) == 2 { + conf, err := strconv.ParseFloat(fields[1], 64) + if err != nil { + continue + } + totalconf += conf + num += 1 + } + } + if num <= 0 { + return 0, nil + } + avg := totalconf / float64(num) + return avg, nil +} + +// Note this only processes one line at a time +func GetLineDetails(probfn string) (line.Details, error) { + var l line.Detail + lines := make(line.Details, 0) + + avg, err := getLineAvg(probfn) + if err != nil { + return lines, err + } + + filebase := strings.Replace(probfn, ".prob", "", 1) + + txt, err := ioutil.ReadFile(filebase + ".txt") + if err != nil { + return lines, err + } + + l.Name = filepath.Base(filebase) + l.Avgconf = avg + l.Text = string(txt) + l.OcrName = filepath.Base(filepath.Dir(filebase)) + + var imgfn line.ImgPath + imgfn.Path = filebase + ".bin.png" + l.Img = imgfn + + lines = append(lines, l) + + return lines, nil +} -- cgit v1.2.1-24-ge1ad