nats
Paulo Simão 2021-11-04 13:05:27 -03:00
parent a1ee372710
commit a010f26d67
1 changed files with 99 additions and 63 deletions

View File

@ -3,8 +3,11 @@ package ocr
import ( import (
"encoding/xml" "encoding/xml"
"go.digitalcircle.com.br/open/replaycli-go/api" "go.digitalcircle.com.br/open/replaycli-go/api"
"log"
) )
const ScreenShot = "ss"
type AltoString struct { type AltoString struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
ID string `xml:"ID,attr"` ID string `xml:"ID,attr"`
@ -14,7 +17,25 @@ type AltoString struct {
HEIGHT int `xml:"HEIGHT,attr"` HEIGHT int `xml:"HEIGHT,attr"`
WC float64 `xml:"WC,attr"` WC float64 `xml:"WC,attr"`
CONTENT string `xml:"CONTENT,attr"` CONTENT string `xml:"CONTENT,attr"`
RHPOS int `xml:"RHPOS,attr"`
RVPOS int `xml:"RVPOS,attr"`
RWIDTH int `xml:"RWIDTH,attr"`
RHEIGHT int `xml:"RHEIGHT,attr"`
} }
func (a *AltoString) AbsCoords(q *Opts) {
nx := int(float64(a.HPOS)/q.Proportion) + q.X
ny := int(float64(a.VPOS)/q.Proportion) + q.Y
nw := int(float64(a.WIDTH) / q.Proportion)
nh := int(float64(a.HEIGHT) / q.Proportion)
log.Printf("Mapping: x: %v=>%v; y:%v=>%v; w:%v=>%v; h:%v=>%v;(Prop: %v,qx: %v, qy: %v)", a.HPOS, nx, a.VPOS, ny, a.WIDTH, nw, a.HEIGHT, nh, q.Proportion, q.X, q.Y)
a.RHPOS = nx
a.RVPOS = ny
a.RWIDTH = nw
a.RHEIGHT = nh
return
}
type AltoSP struct { type AltoSP struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
WIDTH int `xml:"WIDTH,attr"` WIDTH int `xml:"WIDTH,attr"`
@ -28,8 +49,8 @@ type AltoTextLine struct {
VPOS string `xml:"VPOS,attr"` VPOS string `xml:"VPOS,attr"`
WIDTH string `xml:"WIDTH,attr"` WIDTH string `xml:"WIDTH,attr"`
HEIGHT string `xml:"HEIGHT,attr"` HEIGHT string `xml:"HEIGHT,attr"`
String []AltoString `xml:"String"` String []*AltoString `xml:"String"`
SP []AltoSP `xml:"SP"` SP []*AltoSP `xml:"SP"`
} }
type AltoTextBlock struct { type AltoTextBlock struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
@ -38,7 +59,7 @@ type AltoTextBlock struct {
VPOS int `xml:"VPOS,attr"` VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"` WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"` HEIGHT int `xml:"HEIGHT,attr"`
TextLine []AltoTextLine `xml:"TextLine"` TextLine []*AltoTextLine `xml:"TextLine"`
} }
type AltoComposedBlock struct { type AltoComposedBlock struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
@ -47,7 +68,7 @@ type AltoComposedBlock struct {
VPOS int `xml:"VPOS,attr"` VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"` WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"` HEIGHT int `xml:"HEIGHT,attr"`
TextBlock []AltoTextBlock `xml:"TextBlock"` TextBlock []*AltoTextBlock `xml:"TextBlock"`
} }
type AltoPrintSpace struct { type AltoPrintSpace struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
@ -55,7 +76,7 @@ type AltoPrintSpace struct {
VPOS int `xml:"VPOS,attr"` VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"` WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"` HEIGHT int `xml:"HEIGHT,attr"`
ComposedBlock []AltoComposedBlock `xml:"ComposedBlock"` ComposedBlock []*AltoComposedBlock `xml:"ComposedBlock"`
} }
type AltoPage struct { type AltoPage struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
@ -63,7 +84,7 @@ type AltoPage struct {
HEIGHT int `xml:"HEIGHT,attr"` HEIGHT int `xml:"HEIGHT,attr"`
PHYSICALIMGNR string `xml:"PHYSICAL_IMG_NR,attr"` PHYSICALIMGNR string `xml:"PHYSICAL_IMG_NR,attr"`
ID string `xml:"ID,attr"` ID string `xml:"ID,attr"`
PrintSpace AltoPrintSpace `xml:"PrintSpace"` PrintSpace *AltoPrintSpace `xml:"PrintSpace"`
} }
type AltoDescription struct { type AltoDescription struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
@ -72,7 +93,7 @@ type AltoDescription struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
FileName string `xml:"fileName"` FileName string `xml:"fileName"`
} `xml:"sourceImageInformation"` } `xml:"sourceImageInformation"`
OCRProcessing struct { OCRProcessing *struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
ID string `xml:"ID,attr"` ID string `xml:"ID,attr"`
OcrProcessingStep struct { OcrProcessingStep struct {
@ -86,7 +107,7 @@ type AltoDescription struct {
} }
type AltoLayout struct { type AltoLayout struct {
Text string `xml:",chardata"` Text string `xml:",chardata"`
Page AltoPage `xml:"Page"` Page *AltoPage `xml:"Page"`
} }
type Alto struct { type Alto struct {
XMLName xml.Name `xml:"alto"` XMLName xml.Name `xml:"alto"`
@ -95,12 +116,12 @@ type Alto struct {
Xlink string `xml:"xlink,attr"` Xlink string `xml:"xlink,attr"`
Xsi string `xml:"xsi,attr"` Xsi string `xml:"xsi,attr"`
SchemaLocation string `xml:"schemaLocation,attr"` SchemaLocation string `xml:"schemaLocation,attr"`
Description AltoDescription `xml:"Description"` Description *AltoDescription `xml:"Description"`
Layout AltoLayout `xml:"Layout"` Layout *AltoLayout `xml:"Layout"`
} }
func (a Alto) Strings() []AltoString { func (a *Alto) Strings() []*AltoString {
ret := make([]AltoString, 0) ret := make([]*AltoString, 0)
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock { for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
for _, v1 := range v.TextBlock { for _, v1 := range v.TextBlock {
for _, v2 := range v1.TextLine { for _, v2 := range v1.TextLine {
@ -112,6 +133,18 @@ func (a Alto) Strings() []AltoString {
} }
return ret return ret
} }
func (a *Alto) CalcAbsolute(q *Opts) {
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
for _, v1 := range v.TextBlock {
for _, v2 := range v1.TextLine {
for _, v3 := range v2.String {
v3.AbsCoords(q)
}
}
}
}
}
type Opts struct { type Opts struct {
Ver string `json:"ver,omitempty"` Ver string `json:"ver,omitempty"`
@ -130,6 +163,9 @@ type Opts struct {
Src string `json:"src"` Src string `json:"src"`
Bytes []byte `json:"bytes"` Bytes []byte `json:"bytes"`
AddRects bool `json:"add_rects"` AddRects bool `json:"add_rects"`
Proportion float64 `json:"proportion"`
Encoding string `json:"encoding"`
Absolute bool `json:"absolute"`
} }
type Cli struct { type Cli struct {