fix ocr
parent
a1ee372710
commit
a010f26d67
|
@ -3,8 +3,11 @@ package ocr
|
|||
import (
|
||||
"encoding/xml"
|
||||
"go.digitalcircle.com.br/open/replaycli-go/api"
|
||||
"log"
|
||||
)
|
||||
|
||||
const ScreenShot = "ss"
|
||||
|
||||
type AltoString struct {
|
||||
Text string `xml:",chardata"`
|
||||
ID string `xml:"ID,attr"`
|
||||
|
@ -14,7 +17,25 @@ type AltoString struct {
|
|||
HEIGHT int `xml:"HEIGHT,attr"`
|
||||
WC float64 `xml:"WC,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 {
|
||||
Text string `xml:",chardata"`
|
||||
WIDTH int `xml:"WIDTH,attr"`
|
||||
|
@ -28,8 +49,8 @@ type AltoTextLine struct {
|
|||
VPOS string `xml:"VPOS,attr"`
|
||||
WIDTH string `xml:"WIDTH,attr"`
|
||||
HEIGHT string `xml:"HEIGHT,attr"`
|
||||
String []AltoString `xml:"String"`
|
||||
SP []AltoSP `xml:"SP"`
|
||||
String []*AltoString `xml:"String"`
|
||||
SP []*AltoSP `xml:"SP"`
|
||||
}
|
||||
type AltoTextBlock struct {
|
||||
Text string `xml:",chardata"`
|
||||
|
@ -38,7 +59,7 @@ type AltoTextBlock struct {
|
|||
VPOS int `xml:"VPOS,attr"`
|
||||
WIDTH int `xml:"WIDTH,attr"`
|
||||
HEIGHT int `xml:"HEIGHT,attr"`
|
||||
TextLine []AltoTextLine `xml:"TextLine"`
|
||||
TextLine []*AltoTextLine `xml:"TextLine"`
|
||||
}
|
||||
type AltoComposedBlock struct {
|
||||
Text string `xml:",chardata"`
|
||||
|
@ -47,7 +68,7 @@ type AltoComposedBlock struct {
|
|||
VPOS int `xml:"VPOS,attr"`
|
||||
WIDTH int `xml:"WIDTH,attr"`
|
||||
HEIGHT int `xml:"HEIGHT,attr"`
|
||||
TextBlock []AltoTextBlock `xml:"TextBlock"`
|
||||
TextBlock []*AltoTextBlock `xml:"TextBlock"`
|
||||
}
|
||||
type AltoPrintSpace struct {
|
||||
Text string `xml:",chardata"`
|
||||
|
@ -55,7 +76,7 @@ type AltoPrintSpace struct {
|
|||
VPOS int `xml:"VPOS,attr"`
|
||||
WIDTH int `xml:"WIDTH,attr"`
|
||||
HEIGHT int `xml:"HEIGHT,attr"`
|
||||
ComposedBlock []AltoComposedBlock `xml:"ComposedBlock"`
|
||||
ComposedBlock []*AltoComposedBlock `xml:"ComposedBlock"`
|
||||
}
|
||||
type AltoPage struct {
|
||||
Text string `xml:",chardata"`
|
||||
|
@ -63,7 +84,7 @@ type AltoPage struct {
|
|||
HEIGHT int `xml:"HEIGHT,attr"`
|
||||
PHYSICALIMGNR string `xml:"PHYSICAL_IMG_NR,attr"`
|
||||
ID string `xml:"ID,attr"`
|
||||
PrintSpace AltoPrintSpace `xml:"PrintSpace"`
|
||||
PrintSpace *AltoPrintSpace `xml:"PrintSpace"`
|
||||
}
|
||||
type AltoDescription struct {
|
||||
Text string `xml:",chardata"`
|
||||
|
@ -72,7 +93,7 @@ type AltoDescription struct {
|
|||
Text string `xml:",chardata"`
|
||||
FileName string `xml:"fileName"`
|
||||
} `xml:"sourceImageInformation"`
|
||||
OCRProcessing struct {
|
||||
OCRProcessing *struct {
|
||||
Text string `xml:",chardata"`
|
||||
ID string `xml:"ID,attr"`
|
||||
OcrProcessingStep struct {
|
||||
|
@ -86,7 +107,7 @@ type AltoDescription struct {
|
|||
}
|
||||
type AltoLayout struct {
|
||||
Text string `xml:",chardata"`
|
||||
Page AltoPage `xml:"Page"`
|
||||
Page *AltoPage `xml:"Page"`
|
||||
}
|
||||
type Alto struct {
|
||||
XMLName xml.Name `xml:"alto"`
|
||||
|
@ -95,12 +116,12 @@ type Alto struct {
|
|||
Xlink string `xml:"xlink,attr"`
|
||||
Xsi string `xml:"xsi,attr"`
|
||||
SchemaLocation string `xml:"schemaLocation,attr"`
|
||||
Description AltoDescription `xml:"Description"`
|
||||
Layout AltoLayout `xml:"Layout"`
|
||||
Description *AltoDescription `xml:"Description"`
|
||||
Layout *AltoLayout `xml:"Layout"`
|
||||
}
|
||||
|
||||
func (a Alto) Strings() []AltoString {
|
||||
ret := make([]AltoString, 0)
|
||||
func (a *Alto) Strings() []*AltoString {
|
||||
ret := make([]*AltoString, 0)
|
||||
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
|
||||
for _, v1 := range v.TextBlock {
|
||||
for _, v2 := range v1.TextLine {
|
||||
|
@ -112,6 +133,18 @@ func (a Alto) Strings() []AltoString {
|
|||
}
|
||||
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 {
|
||||
Ver string `json:"ver,omitempty"`
|
||||
|
@ -130,6 +163,9 @@ type Opts struct {
|
|||
Src string `json:"src"`
|
||||
Bytes []byte `json:"bytes"`
|
||||
AddRects bool `json:"add_rects"`
|
||||
Proportion float64 `json:"proportion"`
|
||||
Encoding string `json:"encoding"`
|
||||
Absolute bool `json:"absolute"`
|
||||
}
|
||||
|
||||
type Cli struct {
|
||||
|
|
Loading…
Reference in New Issue